forked from tripal/tripal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '4.x' into tv4g1-1509-sequence-fields
- Loading branch information
Showing
6 changed files
with
706 additions
and
4 deletions.
There are no files selected for viewing
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
59 changes: 59 additions & 0 deletions
59
tripal_chado/src/Plugin/Field/FieldFormatter/ChadoSynonymFormatterDefault.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,59 @@ | ||
<?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_synonym_formatter_default", | ||
* label = @Translation("Chado Synonym Formatter"), | ||
* description = @Translation("A chado synonym formatter"), | ||
* field_types = { | ||
* "chado_synonym_default" | ||
* } | ||
* ) | ||
*/ | ||
class ChadoSynonymFormatterDefault extends ChadoFormatterBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function viewElements(FieldItemListInterface $items, $langcode) { | ||
$elements = []; | ||
|
||
$list = []; | ||
foreach($items as $delta => $item) { | ||
$value = $item->get('name')->getString(); | ||
$list[$delta] = $value; | ||
} | ||
|
||
// Also need to make sure to not return markup if the field is empty. | ||
if (empty($list)) { | ||
return $elements; | ||
} | ||
|
||
// If more than one value has been found display all values in an unordered | ||
// list. | ||
if (count($list) > 1) { | ||
$elements[0] = [ | ||
'#theme' => 'item_list', | ||
'#list_type' => 'ul', | ||
'#items' => $list, | ||
'#wrapper_attributes' => ['class' => 'container'], | ||
]; | ||
return $elements; | ||
} | ||
|
||
$elements[0] = [ | ||
'#type' => 'markup', | ||
"#markup" => $list[0] | ||
]; | ||
return $elements; | ||
} | ||
} |
Oops, something went wrong.