archivesspace-8.x-1.x-dev/src/Plugin/Field/FieldWidget/ASExtentWidget.php

src/Plugin/Field/FieldWidget/ASExtentWidget.php
<?php

namespace Drupal\archivesspace\Plugin\Field\FieldWidget;

use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface;

/**
 * Plugin implementation of the 'as_extent_default' widget.
 *
 * @FieldWidget(
 *   id = "as_extent_default",
 *   label = @Translation("ArchivesSpace Extent Widget"),
 *   field_types = {
 *     "as_extent"
 *   }
 * )
 */
class ASExtentWidget extends WidgetBase {

  /**
   * {@inheritdoc}
   */
  public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
    // Item of interest.
    $item =& $items[$delta];
    $settings = $item->getFieldDefinition()->getSettings();

    // Load up the form fields.
    $element += [
      '#type' => 'fieldset',
    ];
    $element['portion'] = [
      '#title' => $this->t('Portion'),
      '#type' => 'select',
      '#options' => $settings['portion_values'],
      '#default_value' => $item->portion ?? '',
    ];
    $element['number'] = [
      '#title' => $this->t('Number'),
      '#type' => 'textfield',
      '#default_value' => $item->number ?? '',
    ];
    $element['extent_type'] = [
      '#title' => $this->t('Type'),
      '#type' => 'select',
      '#options' => $settings['extent_types'],
      '#default_value' => $item->extent_type ?? '',
    ];
    $element['container_summary'] = [
      '#title' => $this->t('Container Summary'),
      '#type' => 'textfield',
      '#default_value' => $item->container_summary ?? '',
    ];
    $element['physical_details'] = [
      '#title' => $this->t('Physical Details'),
      '#type' => 'textfield',
      '#default_value' => $item->physical_details ?? '',
    ];
    $element['dimensions'] = [
      '#title' => $this->t('Dimensions'),
      '#type' => 'textfield',
      '#default_value' => $item->dimensions ?? '',
    ];

    return $element;
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc