propertyDefinitions example

if (isset($this->propertyDefinitions[$name])) {
      return $this->propertyDefinitions[$name];
    }
  }

  /** * {@inheritdoc} */
  public function getPropertyDefinitions() {
    if (!isset($this->propertyDefinitions)) {
      $class = $this->getItemDefinition()->getClass();
      $this->propertyDefinitions = $class::propertyDefinitions($this);
    }
    return $this->propertyDefinitions;
  }

  /** * {@inheritdoc} */
  public function getPropertyNames() {
    return array_keys($this->getPropertyDefinitions());
  }

  
$target_type = $field_definition->getSetting('target_type');
    try {
      $target_type_info = \Drupal::entityTypeManager()->getDefinition($target_type);
    }
    catch (PluginNotFoundException $e) {
      throw new FieldException(sprintf("Field '%s' on entity type '%s' references a target entity type '%s' which does not exist.",
        $field_definition->getName(),
        $field_definition->getTargetEntityTypeId(),
        $target_type
      ));
    }
    $properties = static::propertyDefinitions($field_definition)['target_id'];
    if ($target_type_info->entityClassImplements(FieldableEntityInterface::class) && $properties->getDataType() === 'integer') {
      $columns = [
        'target_id' => [
          'description' => 'The ID of the target entity.',
          'type' => 'int',
          'unsigned' => TRUE,
        ],
      ];
    }
    else {
      $columns = [
        

class FileUriItem extends UriItem {

  /** * {@inheritdoc} */
  public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
    $properties = parent::propertyDefinitions($field_definition);

    $properties['url'] = DataDefinition::create('string')
      ->setLabel(t('Root-relative file URL'))
      ->setComputed(TRUE)
      ->setInternal(FALSE)
      ->setClass(ComputedFileUrl::class);

    return $properties;
  }

}
    $this->enableAllCoreModules();

    /** @var \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager */
    $field_type_manager = \Drupal::service('plugin.manager.field.field_type');
    foreach ($field_type_manager->getDefinitions() as $plugin_id => $definition) {
      $class = $definition['class'];
      $property = $class::mainPropertyName();
      if ($property === NULL) {
        continue;
      }
      $storage_definition = BaseFieldDefinition::create($plugin_id);
      $property_definitions = $class::propertyDefinitions($storage_definition);
      $properties = implode(', ', array_keys($property_definitions));
      if (!empty($property_definitions)) {
        $message = sprintf("%s property %s found in %s", $plugin_id$property$properties);
        $this->assertArrayHasKey($property$class::propertyDefinitions($storage_definition)$message);
      }
    }
  }

  /** * Enable all core modules. */
  

class InternalPropertyTestFieldItem extends StringItem {

  /** * {@inheritdoc} */
  public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
    $properties = parent::propertyDefinitions($field_definition);

    // Add a computed property that is non-internal.     $properties['non_internal_value'] = DataDefinition::create('string')
      ->setLabel(new TranslatableMarkup('Computed string, non-internal property'))
      ->setComputed(TRUE)
      ->setClass(ComputedString::class)
      ->setInternal(FALSE);
    // Add a computed property that is internal.     $properties['internal_value'] = DataDefinition::create('string')
      ->setLabel(new TranslatableMarkup('Computed string, internal property'))
      ->setComputed(TRUE)
      
'table' => 'file_managed',
          'columns' => ['target_id' => 'fid'],
        ],
      ],
    ];
  }

  /** * {@inheritdoc} */
  public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
    $properties = parent::propertyDefinitions($field_definition);

    unset($properties['display']);
    unset($properties['description']);

    $properties['alt'] = DataDefinition::create('string')
      ->setLabel(new TranslatableMarkup('Alternative text'))
      ->setDescription(new TranslatableMarkup("Alternative image text, for the image's 'alt' attribute."));

    $properties['title'] = DataDefinition::create('string')
      ->setLabel(new TranslatableMarkup('Title'))
      ->setDescription(new TranslatableMarkup("Image title text, for the image's 'title' attribute."));

    
if (isset($this->propertyDefinitions[$name])) {
      return $this->propertyDefinitions[$name];
    }
  }

  /** * {@inheritdoc} */
  public function getPropertyDefinitions() {
    if (!isset($this->propertyDefinitions)) {
      $class = $this->getFieldItemClass();
      $this->propertyDefinitions = $class::propertyDefinitions($this);
    }
    return $this->propertyDefinitions;
  }

  /** * {@inheritdoc} */
  public function getPropertyNames() {
    return array_keys($this->getPropertyDefinitions());
  }

  
public static function defaultFieldSettings() {
    return [
      'display_summary' => 0,
      'required_summary' => FALSE,
    ] + parent::defaultFieldSettings();
  }

  /** * {@inheritdoc} */
  public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
    $properties = parent::propertyDefinitions($field_definition);

    $properties['summary'] = DataDefinition::create('string')
      ->setLabel(new TranslatableMarkup('Summary'));

    $properties['summary_processed'] = DataDefinition::create('string')
      ->setLabel(new TranslatableMarkup('Processed summary'))
      ->setDescription(new TranslatableMarkup('The summary text with the text format applied.'))
      ->setComputed(TRUE)
      ->setClass('\Drupal\text\TextProcessed')
      ->setSetting('text source', 'summary');

    
'table' => 'file_managed',
          'columns' => ['target_id' => 'fid'],
        ],
      ],
    ];
  }

  /** * {@inheritdoc} */
  public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
    $properties = parent::propertyDefinitions($field_definition);

    $properties['display'] = DataDefinition::create('boolean')
      ->setLabel(new TranslatableMarkup('Display'))
      ->setDescription(new TranslatableMarkup('Flag to control whether this file should be displayed when viewing content'));

    $properties['description'] = DataDefinition::create('string')
      ->setLabel(new TranslatableMarkup('Description'));

    return $properties;
  }

  

class ShapeItemRequired extends ShapeItem {

  /** * {@inheritdoc} */
  public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
    $properties = parent::propertyDefinitions($field_definition);
    $properties['shape']->setRequired(TRUE);
    return $properties;
  }

}

class SingleInternalPropertyTestFieldItem extends StringItem {

  /** * {@inheritdoc} */
  public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
    $properties = parent::propertyDefinitions($field_definition);

    // Add a computed property that is internal.     $properties['internal_value'] = DataDefinition::create('string')
      ->setLabel(new TranslatableMarkup('Computed string, internal property'))
      ->setComputed(TRUE)
      ->setClass(ComputedString::class);
    return $properties;
  }

}
Home | Imprint | This part of the site doesn't use cookies.