You are here

public function FivestarItem::storageSettingsForm in Fivestar 8

Returns a form for the storage-level settings.

Invoked from \Drupal\field_ui\Form\FieldStorageConfigEditForm to allow administrators to configure storage-level settings.

Field storage might reject settings changes that affect the field storage schema if the storage already has data. When the $has_data parameter is TRUE, the form should not allow changing the settings that take part in the schema() method. It is recommended to set #access to FALSE on the corresponding elements.

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.

bool $has_data: TRUE if the field already has data, FALSE if not.

Return value

array The form definition for the field settings.

Overrides FieldItemBase::storageSettingsForm

File

src/Plugin/Field/FieldType/FivestarItem.php, line 93

Class

FivestarItem
Plugin implementation of the 'fivestar' field type.

Namespace

Drupal\fivestar\Plugin\Field\FieldType

Code

public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) {
  $element = [];
  $vote_manager = \Drupal::service('fivestar.vote_manager');
  $vote_types_link = Link::createFromRoute($this
    ->t('here'), 'entity.vote_type.collection')
    ->toString();
  $element['vote_type'] = [
    '#type' => 'select',
    '#required' => TRUE,
    '#title' => $this
      ->t('Vote type'),
    '#options' => $vote_manager
      ->getVoteTypes(),
    '#description' => $this
      ->t('The vote type this rating will affect. Enter a property on which that this rating will affect, such as <em>quality</em>, <em>satisfaction</em>, <em>overall</em>, etc. You can add new vote type %vote_types_link.', [
      '%vote_types_link' => $vote_types_link,
    ]),
    '#default_value' => $this
      ->getSetting('vote_type'),
    '#disabled' => $has_data,
  ];
  return $element;
}