-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1388 from tripal/tv4g1-292-sequenceField
Tripal 4 Field: Sequence Residues
- Loading branch information
Showing
5 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
tripal_chado/src/Plugin/Field/FieldFormatter/ChadoSequenceFormatterDefault.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#tripal-chado-sequence-format { | ||
font-family: Consolas, monaco, monospace; | ||
font-size: 12px; | ||
height: 195px; /* height set to bisect characters in last row as visible scroll feedback */ | ||
max-width: 400px; | ||
overflow: scroll; | ||
line-height: normal !important; | ||
border: 1px solid #DDDDDD; | ||
padding: 10px; | ||
} |
42 changes: 42 additions & 0 deletions
42
tripal_chado/src/Plugin/Field/FieldFormatter/ChadoSequenceFormatterDefault.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Drupal\tripal_chado\Plugin\Field\FieldFormatter; | ||
|
||
use Drupal\tripal\TripalField\TripalFormatterBase; | ||
use Drupal\Core\Field\FieldItemListInterface; | ||
use Drupal\Core\Form\FormStateInterface; | ||
use Drupal\tripal_chado\TripalField\ChadoFormatterBase; | ||
|
||
/** | ||
* Plugin implementation of Default Tripal field formatter for sequence data | ||
* | ||
* @FieldFormatter( | ||
* id = "chado_sequence_formatter_default", | ||
* label = @Translation("Chado Sequence Residues Display"), | ||
* description = @Translation("Displays chado sequence residues from the feature table on the page."), | ||
* field_types = { | ||
* "chado_sequence_default" | ||
* } | ||
* ) | ||
*/ | ||
class ChadoSequenceFormatterDefault extends ChadoFormatterBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function viewElements(FieldItemListInterface $items, $langcode) { | ||
$elements = []; | ||
$elements['#attached']['library'][] = 'tripal_chado/tripal_chado.field.ChadoSequenceFormatterDefault'; | ||
|
||
foreach($items as $delta => $item) { | ||
$residues = $item->get('residues')->getString(); | ||
if (!empty($residues)) { | ||
$elements[$delta] = [ | ||
"#markup" => "<pre id='tripal-chado-sequence-format'>" . wordwrap($residues,50,'<br>',TRUE) . "</pre>", | ||
]; | ||
} | ||
} | ||
|
||
return $elements; | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
tripal_chado/src/Plugin/Field/FieldType/ChadoSequenceDefault.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
namespace Drupal\tripal_chado\Plugin\Field\FieldType; | ||
|
||
use Drupal\tripal_chado\TripalField\ChadoFieldItemBase; | ||
use Drupal\tripal_chado\TripalStorage\ChadoIntStoragePropertyType; | ||
use Drupal\tripal_chado\TripalStorage\ChadoTextStoragePropertyType; | ||
use Drupal\core\Form\FormStateInterface; | ||
use Drupal\core\Field\FieldDefinitionInterface; | ||
|
||
/** | ||
* Plugin implementation of Default Tripal field for sequence data. | ||
* | ||
* @FieldType( | ||
* id = "chado_sequence_default", | ||
* label = @Translation("Chado Sequence Residues"), | ||
* description = @Translation("Manages sequence residues for content types storing data in the chado feature table."), | ||
* default_widget = "chado_sequence_widget_default", | ||
* default_formatter = "chado_sequence_formatter_default" | ||
* ) | ||
*/ | ||
class ChadoSequenceDefault extends ChadoFieldItemBase { | ||
|
||
public static $id = "chado_sequence_default"; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function mainPropertyName() { | ||
return 'residues'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function defaultFieldSettings() { | ||
$settings = parent::defaultFieldSettings(); | ||
$settings['termIdSpace'] = 'data'; | ||
$settings['termAccession'] = '2044'; | ||
return $settings; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function defaultStorageSettings() { | ||
$settings = parent::defaultStorageSettings(); | ||
$settings['storage_plugin_settings']['base_table'] = 'feature'; | ||
return $settings; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function tripalTypes($field_definition) { | ||
$entity_type_id = $field_definition->getTargetEntityTypeId(); | ||
|
||
// Get the base table columns needed for this field. | ||
$settings = $field_definition->getSetting('storage_plugin_settings'); | ||
|
||
// Get the property terms by using the Chado table columns they map to. | ||
$storage = \Drupal::entityTypeManager()->getStorage('chado_term_mapping'); | ||
$mapping = $storage->load('core_mapping'); | ||
$record_id_term = 'SIO:000729'; | ||
$residues_term = $mapping->getColumnTermId('feature', 'residues'); | ||
|
||
// Return the properties for this field. | ||
$properties = []; | ||
$properties[] = new ChadoIntStoragePropertyType($entity_type_id, self::$id, 'record_id', $record_id_term, [ | ||
'action' => 'store_id', | ||
'drupal_store' => TRUE, | ||
'chado_table' => 'feature', | ||
'chado_column' => 'feature_id' | ||
]); | ||
$properties[] = new ChadoTextStoragePropertyType($entity_type_id, self::$id, 'residues', $residues_term, [ | ||
'action' => 'store', | ||
'chado_column' => 'residues', | ||
'chado_table' => 'feature' | ||
]); | ||
return $properties; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
tripal_chado/src/Plugin/Field/FieldWidget/ChadoSequenceWidgetDefault.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace Drupal\tripal_chado\Plugin\Field\FieldWidget; | ||
|
||
use Drupal\tripal\Plugin\Field\FieldWidget\TripalTextTypeWidget; | ||
use Drupal\tripal\TripalField\TripalWidgetBase; | ||
use Drupal\Core\Field\FieldItemListInterface; | ||
use Drupal\Core\Form\FormStateInterface; | ||
use Drupal\tripal_chado\TripalField\ChadoWidgetBase; | ||
|
||
/** | ||
* Plugin implementation of default Chado Sequence widget. | ||
* | ||
* @FieldWidget( | ||
* id = "chado_sequence_widget_default", | ||
* label = @Translation("Chado Sequence Residues Widget"), | ||
* description = @Translation("The default chado sequence widget which allows curators to manually enter sequence residues on the content edit page."), | ||
* field_types = { | ||
* "chado_sequence_default" | ||
* } | ||
* ) | ||
*/ | ||
class ChadoSequenceWidgetDefault extends ChadoWidgetBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) { | ||
|
||
$item_vals = $items[$delta]->getValue(); | ||
$elements = []; | ||
$elements['record_id'] = [ | ||
'#type' => 'value', | ||
'#default_value' => $item_vals['record_id'] ?? 0, | ||
]; | ||
|
||
$elements['residues'] = $element + [ | ||
'#type' => 'textarea', | ||
'#default_value' => $item_vals['residues'] ?? '', | ||
'#placeholder' => $this->getSetting('placeholder'), | ||
'#attributes' => ['class' => ['js-text-full', 'text-full']], | ||
]; | ||
|
||
return $elements; | ||
} | ||
|
||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function massageFormValues(array $values, array $form, FormStateInterface $form_state) { | ||
|
||
// Remove any empty values that aren't mapped to a record id. | ||
foreach ($values as $val_key => $value) { | ||
$values[$val_key]['residues'] = preg_replace('/\s/', '', $value['residues']); | ||
} | ||
return $values; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters