RelationEndpointItem.php in Relation 8
File
relation_endpoint/src/Plugin/Field/FieldType/RelationEndpointItem.php
View source
<?php
namespace Drupal\relation_endpoint\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\TypedData\DataDefinition;
class RelationEndpointItem extends FieldItemBase {
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['entity_type'] = DataDefinition::create('string')
->setLabel(t('Entity_type of this relation end-point.'));
$properties['entity_id'] = DataDefinition::create('integer')
->setLabel(t('Entity_id of this relation end-point.'));
$properties['r_index'] = DataDefinition::create('integer')
->setLabel(t('The index of this row in this relation.'));
return $properties;
}
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return array(
'columns' => array(
'entity_type' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Entity_type of this relation end-point.',
),
'entity_id' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Entity_id of this relation end-point.',
),
'r_index' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The index of this row in this relation. The highest index in the relation is stored as "arity" in the relation table.',
),
),
'indexes' => array(
'relation' => array(
'entity_type',
'entity_id',
'r_index',
),
),
);
}
public function isEmpty() {
$value = $this
->get('entity_id')
->getValue();
return $value === NULL || $value === '';
}
}