Contributor.php in Bibliography & Citation 8
File
modules/bibcite_entity/src/Plugin/Field/FieldType/Contributor.php
View source
<?php
namespace Drupal\bibcite_entity\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\TypedData\DataDefinition;
class Contributor extends EntityReferenceItem implements ContributorFieldInterface {
public static function defaultStorageSettings() {
return [
'target_type' => 'bibcite_contributor',
] + parent::defaultStorageSettings();
}
public static function defaultFieldSettings() {
return [
'handler' => 'default:bibcite_contributor',
'handler_settings' => [
'auto_create' => TRUE,
'auto_create_bundle' => 'bibcite_contributor',
],
] + parent::defaultFieldSettings();
}
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties = parent::propertyDefinitions($field_definition);
$properties['category'] = DataDefinition::create('string')
->setLabel(new TranslatableMarkup('Category'))
->setSetting('case_sensitive', TRUE);
$properties['role'] = DataDefinition::create('string')
->setLabel(new TranslatableMarkup('Role'))
->setSetting('case_sensitive', TRUE);
return $properties;
}
public static function mainPropertyName() {
return 'target_id';
}
public static function schema(FieldStorageDefinitionInterface $field_definition) {
$schema = parent::schema($field_definition);
$schema['columns']['category'] = [
'type' => 'varchar',
'length' => 255,
];
$schema['columns']['role'] = [
'type' => 'varchar',
'length' => 255,
];
return $schema;
}
public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) {
return [];
}
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
return [];
}
}
Classes
Name |
Description |
Contributor |
Plugin implementation of the 'bibcite_contributor' field type. |