You are here

public function Calendar::buildOptionsForm in Calendar 8

Same name in this branch
  1. 8 src/Plugin/views/style/Calendar.php \Drupal\calendar\Plugin\views\style\Calendar::buildOptionsForm()
  2. 8 src/Plugin/views/row/Calendar.php \Drupal\calendar\Plugin\views\row\Calendar::buildOptionsForm()
Same name and namespace in other branches
  1. 8.2 src/Plugin/views/style/Calendar.php \Drupal\calendar\Plugin\views\style\Calendar::buildOptionsForm()

Provide a form to edit options for this plugin.

Overrides StylePluginBase::buildOptionsForm

File

src/Plugin/views/style/Calendar.php, line 219

Class

Calendar
Views style plugin for the Calendar module.

Namespace

Drupal\calendar\Plugin\views\style

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  $form['calendar_type'] = [
    '#title' => $this
      ->t('Calendar type'),
    '#type' => 'select',
    '#description' => $this
      ->t('Select the calendar time period for this display.'),
    '#default_value' => $this->options['calendar_type'],
    '#options' => CalendarHelper::displayTypes(),
  ];
  $form['mini'] = [
    '#title' => $this
      ->t('Display as mini calendar'),
    '#default_value' => $this->options['mini'],
    '#type' => 'radios',
    '#options' => [
      0 => $this
        ->t('No'),
      1 => $this
        ->t('Yes'),
    ],
    '#description' => $this
      ->t('Display the mini style calendar, with no item details. Suitable for a calendar displayed in a block.'),
    '#dependency' => [
      'edit-style-options-calendar-type' => [
        'month',
      ],
    ],
    '#states' => [
      'visible' => [
        ':input[name="style_options[calendar_type]"]' => [
          'value' => 'month',
        ],
      ],
    ],
  ];
  $form['link_to_date'] = [
    '#title' => $this
      ->t('Link to date'),
    '#default_value' => $this->options['link_to_date'],
    '#type' => 'radios',
    '#options' => [
      0 => $this
        ->t('No'),
      1 => $this
        ->t('Yes'),
    ],
    '#description' => $this
      ->t('Links day to day view'),
    '#dependency' => [
      'edit-style-options-calendar-type' => [
        'month',
      ],
    ],
    '#states' => [
      'visible' => [
        ':input[name="style_options[calendar_type]"]' => [
          'value' => 'month',
        ],
      ],
    ],
  ];
  $form['month_name_size'] = [
    '#title' => $this
      ->t('Calendar month names'),
    '#default_value' => $this->options['month_name_size'],
    '#type' => 'radios',
    '#options' => [
      1 => $this
        ->t('Abbreviated name'),
      99 => $this
        ->t('Full name'),
    ],
    '#description' => $this
      ->t('The way month names should be displayed in a year calendar.'),
    '#states' => [
      'visible' => [
        ':input[name="style_options[calendar_type]"]' => [
          'value' => 'year',
        ],
      ],
    ],
  ];
  $form['name_size'] = [
    '#title' => $this
      ->t('Calendar day of week names'),
    '#default_value' => $this->options['name_size'],
    '#type' => 'radios',
    '#options' => [
      1 => $this
        ->t('First letter of name'),
      2 => $this
        ->t('First two letters of name'),
      3 => $this
        ->t('Abbreviated name'),
      99 => $this
        ->t('Full name'),
    ],
    '#description' => $this
      ->t('The way day of week names should be displayed in a calendar.'),
    '#states' => [
      'visible' => [
        ':input[name="style_options[calendar_type]"]' => [
          [
            'value' => 'year',
          ],
          [
            'value' => 'month',
          ],
          [
            'value' => 'week',
          ],
        ],
      ],
    ],
  ];
  $form['with_weekno'] = [
    '#title' => $this
      ->t('Show week numbers'),
    '#default_value' => $this->options['with_weekno'],
    '#type' => 'radios',
    '#options' => [
      0 => $this
        ->t('No'),
      1 => $this
        ->t('Yes'),
    ],
    '#description' => $this
      ->t('Whether or not to show week numbers in the left column of calendar weeks and months.'),
    '#states' => [
      'visible' => [
        ':input[name="style_options[calendar_type]"]' => [
          'value' => 'month',
        ],
      ],
    ],
  ];
  $form['max_items'] = [
    '#title' => $this
      ->t('Maximum items'),
    '#type' => 'select',
    '#options' => [
      0 => $this
        ->t('Unlimited'),
      1 => $this
        ->formatPlural(1, '1 item', '@count items'),
      3 => $this
        ->formatPlural(3, '1 item', '@count items'),
      5 => $this
        ->formatPlural(5, '1 item', '@count items'),
      10 => $this
        ->formatPlural(10, '1 item', '@count items'),
    ],
    '#default_value' => $this->options['calendar_type'] != 'day' ? $this->options['max_items'] : 0,
    '#description' => $this
      ->t('Maximum number of items to show in calendar cells, used to keep the calendar from expanding to a huge size when there are lots of items in one day.'),
    '#states' => [
      'visible' => [
        ':input[name="style_options[calendar_type]"]' => [
          'value' => 'month',
        ],
      ],
    ],
  ];
  $form['max_items_behavior'] = [
    '#title' => $this
      ->t('Too many items'),
    '#type' => 'select',
    '#options' => [
      'more' => $this
        ->t("Show maximum, add 'more' link"),
      'hide' => $this
        ->t('Hide all, add link to day'),
    ],
    '#default_value' => $this->options['calendar_type'] != 'day' ? $this->options['max_items_behavior'] : 'more',
    '#description' => $this
      ->t('Behavior when there are more than the above number of items in a single day. When there more items than this limit, a link to the day view will be displayed.'),
    '#states' => [
      'visible' => [
        ':input[name="style_options[calendar_type]"]' => [
          'value' => 'month',
        ],
      ],
    ],
  ];
  $form['groupby_times'] = [
    '#title' => $this
      ->t('Time grouping'),
    '#type' => 'select',
    '#default_value' => $this->options['groupby_times'],
    '#description' => $this
      ->t("Group items together into time periods based on their start time."),
    '#options' => [
      '' => $this
        ->t('None'),
      'hour' => $this
        ->t('Hour'),
      'half' => $this
        ->t('Half hour'),
      'custom' => $this
        ->t('Custom'),
    ],
    '#states' => [
      'visible' => [
        ':input[name="style_options[calendar_type]"]' => [
          [
            'value' => 'day',
          ],
          [
            'value' => 'week',
          ],
        ],
      ],
    ],
  ];
  $form['groupby_times_custom'] = [
    '#title' => $this
      ->t('Custom time grouping'),
    '#type' => 'textarea',
    '#default_value' => $this->options['groupby_times_custom'],
    '#description' => $this
      ->t("When choosing the 'custom' Time grouping option above, create custom time period groupings as a comma-separated list of 24-hour times in the format HH:MM:SS, like '00:00:00,08:00:00,18:00:00'. Be sure to start with '00:00:00'. All items after the last time will go in the final group."),
    '#states' => [
      'visible' => [
        ':input[name="style_options[groupby_times]"]' => [
          'value' => 'custom',
        ],
      ],
    ],
  ];
  $form['theme_style'] = [
    '#title' => $this
      ->t('Overlapping time style'),
    '#default_value' => $this->options['theme_style'],
    '#type' => 'select',
    '#options' => [
      0 => $this
        ->t('Do not display overlapping items'),
      1 => $this
        ->t('Display overlapping items, with scrolling'),
      2 => $this
        ->t('Display overlapping items, no scrolling'),
    ],
    '#description' => $this
      ->t('Select whether calendar items are displayed as overlapping items. Use scrolling to shrink the window and focus on the selected items, or omit scrolling to display the whole day. This only works if hour or half hour time grouping is chosen!'),
    '#states' => [
      'visible' => [
        ':input[name="style_options[calendar_type]"]' => [
          [
            'value' => 'day',
          ],
          [
            'value' => 'week',
          ],
        ],
      ],
    ],
  ];

  // Create a list of fields that are available for grouping.
  $field_options = [];
  $fields = $this->view->display_handler
    ->getOption('fields');
  foreach ($fields as $field_name => $field) {
    $field_options[$field_name] = $field['field'];
  }
  $form['groupby_field'] = [
    '#title' => $this
      ->t('Field grouping'),
    '#type' => 'select',
    '#default_value' => $this->options['groupby_field'],
    '#description' => $this
      ->t("Optionally group items into columns by a field value, for instance select the content type to show items for each content type in their own column, or use a location field to organize items into columns by location. NOTE! This is incompatible with the overlapping style option."),
    '#options' => [
      '' => '',
    ] + $field_options,
    '#states' => [
      'visible' => [
        ':input[name="style_options[calendar_type]"]' => [
          'value' => 'day',
        ],
      ],
    ],
  ];
  $form['multiday_theme'] = [
    '#title' => $this
      ->t('Multi-day style'),
    '#default_value' => $this->options['multiday_theme'],
    '#type' => 'select',
    '#options' => [
      0 => $this
        ->t('Display multi-day item as a single column'),
      1 => $this
        ->t('Display multi-day item as a multiple column row'),
    ],
    '#description' => $this
      ->t('If selected, items which span multiple days will displayed as a multi-column row.  If not selected, items will be displayed as an individual column.'),
    '#states' => [
      'visible' => [
        ':input[name="style_options[calendar_type]"]' => [
          [
            'value' => 'month',
          ],
          [
            'value' => 'week',
          ],
        ],
      ],
    ],
  ];
  $form['multiday_hidden'] = [
    '#title' => $this
      ->t('Fields to hide in Multi-day rows'),
    '#default_value' => $this->options['multiday_hidden'],
    '#type' => 'checkboxes',
    '#options' => $field_options,
    '#description' => $this
      ->t('Choose fields to hide when displayed in multi-day rows. Usually you only want to see the title or Colorbox selector in multi-day rows and would hide all other fields.'),
    '#states' => [
      'visible' => [
        ':input[name="style_options[calendar_type]"]' => [
          [
            'value' => 'month',
          ],
          [
            'value' => 'week',
          ],
          [
            'value' => 'day',
          ],
        ],
      ],
    ],
  ];

  // Allow custom Day and Week links.
  $form['granularity_links'] = [
    '#tree' => TRUE,
  ];
  $form['granularity_links']['day'] = [
    '#title' => $this
      ->t('Day link displays'),
    '#type' => 'select',
    '#default_value' => $this->options['granularity_links']['day'],
    '#description' => $this
      ->t("Optionally select a View display to use for Day links."),
    '#options' => [
      '' => $this
        ->t('Default display'),
    ] + $this
      ->viewOptionsForGranularity('day'),
  ];
  $form['granularity_links']['week'] = [
    '#title' => $this
      ->t('Week link displays'),
    '#type' => 'select',
    '#default_value' => $this->options['granularity_links']['week'],
    '#description' => $this
      ->t("Optionally select a View display to use for Week links."),
    '#options' => [
      '' => $this
        ->t('Default display'),
    ] + $this
      ->viewOptionsForGranularity('week'),
  ];
  $form['granularity_links']['month'] = [
    '#title' => $this
      ->t('Month link displays'),
    '#type' => 'select',
    '#default_value' => $this->options['granularity_links']['month'],
    '#description' => $this
      ->t("Optionally select a View display to use for Month links."),
    '#options' => [
      '' => $this
        ->t('Default display'),
    ] + $this
      ->viewOptionsForGranularity('month'),
  ];
}