-
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 #1555 from tripal/tv4g1-issue1551-Add-chado-boolea…
…n-field Tripal 4 add a chado boolean field
- Loading branch information
Showing
14 changed files
with
862 additions
and
10 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
37 changes: 37 additions & 0 deletions
37
tripal/src/Plugin/Field/FieldFormatter/DefaultTripalBooleanTypeFormatter.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,37 @@ | ||
<?php | ||
|
||
namespace Drupal\tripal\Plugin\Field\FieldFormatter; | ||
|
||
use Drupal\tripal\TripalField\TripalFormatterBase; | ||
use Drupal\Core\Field\FieldItemListInterface; | ||
use Drupal\Core\Form\FormStateInterface; | ||
|
||
/** | ||
* Plugin implementation of default Tripal boolean type formatter. | ||
* | ||
* @FieldFormatter( | ||
* id = "default_tripal_boolean_type_formatter", | ||
* label = @Translation("Default Boolean Type Formatter"), | ||
* description = @Translation("The default boolean type formatter."), | ||
* field_types = { | ||
* "tripal_boolean_type" | ||
* } | ||
* ) | ||
*/ | ||
class DefaultTripalBooleanTypeFormatter extends TripalFormatterBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function viewElements(FieldItemListInterface $items, $langcode) { | ||
$elements = []; | ||
|
||
foreach($items as $delta => $item) { | ||
$elements[$delta] = [ | ||
"#markup" => $item->get("value")->getValue() ? 'True' : 'False', | ||
]; | ||
} | ||
|
||
return $elements; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
tripal/src/Plugin/Field/FieldType/TripalBooleanTypeItem.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,39 @@ | ||
<?php | ||
|
||
namespace Drupal\tripal\Plugin\Field\FieldType; | ||
|
||
use Drupal\tripal\TripalField\TripalFieldItemBase; | ||
use Drupal\tripal\TripalStorage\BoolStoragePropertyType; | ||
use Drupal\tripal\TripalStorage\StoragePropertyValue; | ||
use Drupal\core\Form\FormStateInterface; | ||
use Drupal\core\Field\FieldDefinitionInterface; | ||
|
||
/** | ||
* Plugin implementation of the 'boolean' field type. | ||
* | ||
* @FieldType( | ||
* id = "tripal_boolean_type", | ||
* label = @Translation("Tripal Boolean Field Type"), | ||
* description = @Translation("A boolean field."), | ||
* default_widget = "default_tripal_boolean_type_widget", | ||
* default_formatter = "default_tripal_boolean_type_formatter" | ||
* ) | ||
*/ | ||
class TripalBooleanTypeItem extends TripalFieldItemBase { | ||
|
||
public static $id = "tripal_boolean_type"; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function tripalTypes($field_definition) { | ||
$entity_type_id = $field_definition->getTargetEntityTypeId(); | ||
$storage_settings = $field_definition->getSettings(); | ||
$termIdSpace = $storage_settings['termIdSpace']; | ||
$termAccession = $storage_settings['termAccession']; | ||
|
||
return [ | ||
new BoolStoragePropertyType($entity_type_id, self::$id, "value", $termIdSpace . ':' . $termAccession), | ||
]; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
tripal/src/Plugin/Field/FieldWidget/TripalBooleanTypeWidget.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,35 @@ | ||
<?php | ||
|
||
namespace Drupal\tripal\Plugin\Field\FieldWidget; | ||
|
||
use Drupal\tripal\TripalField\TripalWidgetBase; | ||
use Drupal\Core\Field\FieldItemListInterface; | ||
use Drupal\Core\Form\FormStateInterface; | ||
|
||
/** | ||
* Plugin implementation of default Tripal boolean type widget. | ||
* | ||
* @FieldWidget( | ||
* id = "default_tripal_boolean_type_widget", | ||
* label = @Translation("Tripal Boolean Widget"), | ||
* description = @Translation("The default boolean type widget."), | ||
* field_types = { | ||
* "tripal_boolean_type" | ||
* } | ||
* ) | ||
*/ | ||
class TripalBooleanTypeWidget extends TripalWidgetBase { | ||
|
||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) { | ||
$element['value'] = $element + [ | ||
'#type' => 'checkbox', | ||
'#default_value' => $items[$delta]->value ?? NULL, | ||
'#placeholder' => $this->getSetting('placeholder'), | ||
]; | ||
return $element; | ||
} | ||
} |
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
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
Oops, something went wrong.