3 namespace Drupal\layout_builder\Plugin\Field\FieldType;
5 use Drupal\Core\Field\FieldDefinitionInterface;
6 use Drupal\Core\Field\FieldItemBase;
7 use Drupal\Core\Field\FieldStorageDefinitionInterface;
8 use Drupal\Core\StringTranslation\TranslatableMarkup;
9 use Drupal\Core\TypedData\DataDefinition;
10 use Drupal\layout_builder\Section;
13 * Plugin implementation of the 'layout_section' field type.
18 * id = "layout_section",
19 * label = @Translation("Layout Section"),
20 * description = @Translation("Layout Section"),
21 * list_class = "\Drupal\layout_builder\Field\LayoutSectionItemList",
23 * cardinality = \Drupal\Core\Field\FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED
26 * @property \Drupal\layout_builder\Section section
28 class LayoutSectionItem extends FieldItemBase {
33 public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
34 $properties['section'] = DataDefinition::create('layout_section')
35 ->setLabel(new TranslatableMarkup('Layout Section'))
44 public function __get($name) {
45 // @todo \Drupal\Core\Field\FieldItemBase::__get() does not return default
46 // values for uninstantiated properties. This will forcibly instantiate
47 // all properties with the side-effect of a performance hit, resolve
48 // properly in https://www.drupal.org/node/2413471.
49 $this->getProperties();
51 return parent::__get($name);
57 public static function mainPropertyName() {
64 public static function schema(FieldStorageDefinitionInterface $field_definition) {
81 public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
82 // @todo Expand this in https://www.drupal.org/node/2912331.
83 $values['section'] = new Section('layout_onecol');
90 public function isEmpty() {
91 return empty($this->section);