You are here

public function RecipeML::buildOptionsForm in Recipe 8.2

Provide a form to edit options for this plugin.

Overrides StylePluginBase::buildOptionsForm

File

src/Plugin/views/style/RecipeML.php, line 98
Copyright (c) FormatData. All rights reserved.

Class

RecipeML
Default style plugin to render RecipeML.

Namespace

Drupal\recipe\Plugin\views\style

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  $initial_labels = [
    '' => $this
      ->t('- None -'),
  ];
  $view_fields_labels = $this->displayHandler
    ->getFieldLabels();
  $view_fields_labels = array_merge($initial_labels, $view_fields_labels);
  $form['title_field'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Title field'),
    '#description' => $this
      ->t('The field that is going to be used as the recipe title for each row.'),
    '#options' => $view_fields_labels,
    '#default_value' => $this->options['title_field'],
    '#required' => TRUE,
  ];
  $form['version_field'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Version field'),
    '#description' => $this
      ->t('The field that is going to be used as the recipe version for each row.'),
    '#options' => $view_fields_labels,
    '#default_value' => $this->options['version_field'],
  ];
  $form['source_field'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Source field'),
    '#description' => $this
      ->t('The field that is going to be used as the recipe source for each row.'),
    '#options' => $view_fields_labels,
    '#default_value' => $this->options['source_field'],
  ];
  $form['time_fields'] = [
    '#type' => 'checkboxes',
    '#title' => t('Preptime fields'),
    '#description' => t('Fields that will be used as the recipe preptimes for each row.  Selected fields must be integers.  Note that the RecipeML preptime element may encompass multiple time elements such as the cooking time or total time.  It is not limited to the preparation time.'),
    '#options' => $this->displayHandler
      ->getFieldLabels(),
    '#default_value' => $this->options['time_fields'],
    '#multiple' => TRUE,
  ];
  $form['yield_qty_field'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Yield quantity field'),
    '#description' => $this
      ->t('The field that is going to be used as the recipe yield quantity for each row.'),
    '#options' => $view_fields_labels,
    '#default_value' => $this->options['yield_qty_field'],
  ];
  $form['yield_unit_field'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Yield unit field'),
    '#description' => $this
      ->t('The field that is going to be used as the recipe yield unit for each row.'),
    '#options' => $view_fields_labels,
    '#default_value' => $this->options['yield_unit_field'],
  ];
  $form['description_field'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Description field'),
    '#description' => $this
      ->t('The field that is going to be used as the recipe description for each row.'),
    '#options' => $view_fields_labels,
    '#default_value' => $this->options['description_field'],
  ];
  $form['ingredients_field'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Ingredients field'),
    '#description' => $this
      ->t('The field that is going to be used as the recipe ingredients for each row.'),
    '#options' => $view_fields_labels,
    '#default_value' => $this->options['ingredients_field'],
    '#required' => TRUE,
  ];
  $form['directions_field'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Directions field'),
    '#description' => $this
      ->t('The field that is going to be used as the recipe directions for each row.'),
    '#options' => $view_fields_labels,
    '#default_value' => $this->options['directions_field'],
    '#required' => TRUE,
  ];
}