class RgbItem

Same name in other branches
  1. 3.x modules/field_example/src/Plugin/Field/FieldType/RgbItem.php \Drupal\field_example\Plugin\Field\FieldType\RgbItem
  2. 4.0.x modules/field_example/src/Plugin/Field/FieldType/RgbItem.php \Drupal\field_example\Plugin\Field\FieldType\RgbItem

Plugin implementation of the 'field_example_rgb' field type.

Plugin annotation


@FieldType(
  id = "field_example_rgb",
  label = @Translation("Example Color RGB"),
  module = "field_example",
  description = @Translation("Demonstrates a field composed of an RGB color."),
  default_widget = "field_example_text",
  default_formatter = "field_example_simple_text"
)

Hierarchy

  • class \Drupal\field_example\Plugin\Field\FieldType\RgbItem extends \Drupal\Core\Field\FieldItemBase

Expanded class hierarchy of RgbItem

File

field_example/src/Plugin/Field/FieldType/RgbItem.php, line 21

Namespace

Drupal\field_example\Plugin\Field\FieldType
View source
class RgbItem extends FieldItemBase {
    
    /**
     * {@inheritdoc}
     */
    public static function schema(FieldStorageDefinitionInterface $field_definition) {
        return [
            'columns' => [
                'value' => [
                    'type' => 'text',
                    'size' => 'tiny',
                    'not null' => FALSE,
                ],
            ],
        ];
    }
    
    /**
     * {@inheritdoc}
     */
    public function isEmpty() {
        $value = $this->get('value')
            ->getValue();
        return $value === NULL || $value === '';
    }
    
    /**
     * {@inheritdoc}
     */
    public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
        $properties['value'] = DataDefinition::create('string')->setLabel(t('Hex value'));
        return $properties;
    }

}

Members

Title Sort descending Modifiers Object type Summary
RgbItem::isEmpty public function
RgbItem::propertyDefinitions public static function
RgbItem::schema public static function