You are here

public function MinisiteItem::fieldSettingsForm in Mini site 8

Returns a form for the field-level settings.

Invoked from \Drupal\field_ui\Form\FieldConfigEditForm to allow administrators to configure field-level settings.

Parameters

array $form: The form where the settings form is being included in.

\Drupal\Core\Form\FormStateInterface $form_state: The form state of the (entire) configuration form.

Return value

array The form definition for the field settings.

Overrides FileItem::fieldSettingsForm

File

src/Plugin/Field/FieldType/MinisiteItem.php, line 141

Class

MinisiteItem
Plugin implementation of the Minisite field type.

Namespace

Drupal\minisite\Plugin\Field\FieldType

Code

public function fieldSettingsForm(array $form, FormStateInterface $form_state) {

  // Get base form from FileItem.
  $element = parent::fieldSettingsForm($form, $form_state);
  $settings = $this
    ->getSettings();
  $element['file_extensions']['#title'] = $this
    ->t('Allowed archive file extensions');
  if (!\Drupal::currentUser()
    ->hasPermission('administer site configuration')) {
    $element['file_extensions']['#disabled'] = TRUE;
  }

  // Make the extension list a little more human-friendly by comma-separation.
  $extensions = str_replace(' ', ', ', $settings['minisite_extensions']);
  $element['minisite_extensions'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Allowed file extensions in uploaded minisite files'),
    '#default_value' => $extensions,
    '#description' => $this
      ->t('Separate extensions with a space or comma and do not include the leading dot.'),
    '#element_validate' => [
      [
        get_class($this),
        'validateExtensions',
      ],
      [
        get_class($this),
        'validateNoDeniedExtensions',
      ],
    ],
    '#weight' => 11,
    '#maxlength' => 256,
    // By making this field required, we prevent a potential security issue
    // that would allow files of any type to be uploaded.
    '#required' => TRUE,
  ];
  return $element;
}