You are here

public function SubscriptionOrders::settingsForm in Commerce Recurring Framework 8

Returns a form to configure settings for the formatter.

Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the formatter. The field_ui module takes care of handling submitted form values.

Parameters

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

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form elements for the formatter settings.

Overrides FormatterBase::settingsForm

File

src/Plugin/Field/FieldFormatter/SubscriptionOrders.php, line 103

Class

SubscriptionOrders
Plugin implementation of the 'subscription_orders' formatter.

Namespace

Drupal\commerce_recurring\Plugin\Field\FieldFormatter

Code

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

  /** @var \Drupal\Core\Entity\EntityStorageInterface $view_storage */
  $view_storage = $this->entityTypeManager
    ->getStorage('view');

  /** @var \Drupal\Core\Entity\EntityTypeInterface $entity_type */
  $entity_type = $this->entityTypeManager
    ->getDefinition('commerce_order');
  $eligible_views = array_filter($view_storage
    ->loadMultiple(), static function ($view) use ($entity_type) {
    return in_array($view
      ->get('base_table'), [
      $entity_type
        ->getBaseTable(),
      $entity_type
        ->getDataTable(),
    ]);
  });
  $elements = [];
  $options = array_map(static function ($view) {
    return $view
      ->label();
  }, $eligible_views);
  $elements['view'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('View used to display the orders'),
    '#required' => TRUE,
    '#options' => $options,
    '#default_value' => $this
      ->getSetting('view'),
    '#description' => '<p>' . $this
      ->t('Choose the view to use to render the recurring order list for this display. The default display will be used.') . '</p>',
  ];
  return $elements;
}