LibraryItemFieldType.php in Library 8
File
src/Plugin/Field/FieldType/LibraryItemFieldType.php
View source
<?php
namespace Drupal\library\Plugin\Field\FieldType;
use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem;
use Drupal\Core\Form\FormStateInterface;
class LibraryItemFieldType extends EntityReferenceItem {
public static function defaultFieldSettings() {
$settings = parent::defaultFieldSettings();
$settings['due_date'] = 30;
$settings['barcode_generation'] = TRUE;
return $settings;
}
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$elements['due_date'] = [
'#title' => $this
->t('Due date'),
'#type' => 'number',
'#required' => TRUE,
'#min' => 0,
'#default_value' => $this
->getSetting('due_date'),
];
$elements['barcode_generation'] = [
'#title' => $this
->t('Automatically generate barcodes'),
'#type' => 'checkbox',
'#default_value' => $this
->getSetting('barcode_generation'),
];
return $elements;
}
public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) {
$overridden['target_type'] = [
'#type' => 'value',
'#value' => 'library_item',
];
return $overridden;
}
}