You are here

trait OptionsFormHelperTrait in FullCalendar 8.4

Same name and namespace in other branches
  1. 8.5 src/Plugin/fullcalendar/type/OptionsFormHelperTrait.php \Drupal\fullcalendar\Plugin\fullcalendar\type\OptionsFormHelperTrait
  2. 8.2 src/Plugin/fullcalendar/type/OptionsFormHelperTrait.php \Drupal\fullcalendar\Plugin\fullcalendar\type\OptionsFormHelperTrait

Hierarchy

1 file declares its use of OptionsFormHelperTrait
FullCalendar.php in src/Plugin/views/style/FullCalendar.php

File

src/Plugin/fullcalendar/type/OptionsFormHelperTrait.php, line 10

Namespace

Drupal\fullcalendar\Plugin\fullcalendar\type
View source
trait OptionsFormHelperTrait {

  /**
   * Get all FC default options that are supported.
   *
   * @return array
   *   Array of view options.
   */
  public function getDefaultOptions() {
    return [
      'header' => [
        'default' => "left:'title', center:'', right:'today prev,next'",
      ],
      'footer' => [
        'default' => '',
      ],
      'titleFormat' => [
        'default' => '',
      ],
      'titleRangeSeparator' => [
        'default' => '\\u2013',
      ],
      'buttonText' => [
        'default' => "today:'today', month:'month', week:'week', day:'day', list:'list'",
      ],
      'buttonIcons' => [
        'default' => "prev:'left-single-arrow', next:'right-single-arrow', prevYear:'left-double-arrow', nextYear:'right-double-arrow'",
      ],
      'month_view' => [
        'default' => 1,
      ],
      'timegrid_view' => [
        'default' => 1,
      ],
      'list_view' => [
        'default' => 1,
      ],
      'daygrid_view' => [
        'default' => 1,
      ],
      'google' => [
        'contains' => [
          'googleCalendarApiKey' => [
            'default' => '',
          ],
          'googleCalendarId' => [
            'default' => '',
          ],
        ],
      ],
      'month_view_settings' => [
        'contains' => [
          'fixedWeekCount' => [
            'default' => 1,
          ],
          'showNonCurrentDates' => [
            'default' => 1,
          ],
        ],
      ],
      'timegrid_view_settings' => [
        'contains' => [
          'allDaySlot' => [
            'default' => 1,
          ],
          'allDayText' => [
            'default' => 'all-day',
          ],
          'slotEventOverlap' => [
            'default' => 1,
          ],
          'timeGridEventMinHeight' => [
            'default' => '',
          ],
        ],
      ],
      'list_view_settings' => [
        'contains' => [
          'listDayFormat' => [
            'default' => "weekday:'long'",
          ],
          'listDayAltFormat' => [
            'default' => "month:'long', day:'numeric', year:'numeric'",
          ],
          'noEventsMessage' => [
            'default' => 'No events to display',
          ],
        ],
      ],
      'display' => [
        'contains' => [
          'defaultView' => [
            'default' => 'dayGridMonth',
          ],
          'firstDay' => [
            'default' => 0,
          ],
        ],
      ],
      'times' => [
        'contains' => [
          'weekends' => [
            'default' => 1,
          ],
          'hiddenDays' => [
            'default' => '',
          ],
          'columnHeader' => [
            'default' => 1,
          ],
        ],
      ],
      'views_year' => [
        'contains' => [
          'listYear_buttonText' => [
            'default' => "buttonText: 'list'",
          ],
          'listYear_titleFormat' => [
            'default' => "year: 'numeric'",
          ],
        ],
      ],
      'views_month' => [
        'contains' => [
          'listMonth_buttonText' => [
            'default' => "buttonText: 'list'",
          ],
          'listMonth_titleFormat' => [
            'default' => "year: 'numeric', month: 'long'",
          ],
          'dayGridMonth_buttonText' => [
            'default' => "buttonText: 'month'",
          ],
          'dayGridMonth_titleFormat' => [
            'default' => "year: 'numeric', month: 'long'",
          ],
          'dayGridMonth_columnHeaderFormat' => [
            'default' => "weekday:'short'",
          ],
        ],
      ],
      'views_week' => [
        'contains' => [
          'listWeek_buttonText' => [
            'default' => "buttonText: 'list'",
          ],
          'listWeek_titleFormat' => [
            'default' => "year: 'numeric', month: 'short', day: 'numeric'",
          ],
          'dayGridWeek_buttonText' => [
            'default' => "buttonText: 'week'",
          ],
          'dayGridWeek_titleFormat' => [
            'default' => "year: 'numeric', month: 'short', day: 'numeric'",
          ],
          'dayGridWeek_columnHeaderFormat' => [
            'default' => "weekday:'short', month:'numeric', day:'numeric', omitCommas:true",
          ],
          'timeGridWeek_buttonText' => [
            'default' => "buttonText: 'week'",
          ],
          'timeGridWeek_titleFormat' => [
            'default' => "year: 'numeric', month: 'short', day: 'numeric'",
          ],
          'timeGridWeek_columnHeaderFormat' => [
            'default' => "weekday:'short', month:'numeric', day:'numeric', omitCommas:true",
          ],
        ],
      ],
      'views_day' => [
        'contains' => [
          'listDay_buttonText' => [
            'default' => "buttonText: 'list'",
          ],
          'listDay_titleFormat' => [
            'default' => "year: 'numeric', month: 'long', day: 'numeric'",
          ],
          'dayGridDay_buttonText' => [
            'default' => "buttonText: 'day'",
          ],
          'dayGridDay_titleFormat' => [
            'default' => "year: 'numeric', month: 'long', day: 'numeric'",
          ],
          'dayGridDay_columnHeaderFormat' => [
            'default' => "weekday:'long'",
          ],
          'timeGridDay_buttonText' => [
            'default' => "buttonText: 'day'",
          ],
          'timeGridDay_titleFormat' => [
            'default' => "year: 'numeric', month: 'long', day: 'numeric'",
          ],
          'timeGridDay_columnHeaderFormat' => [
            'default' => "weekday:'long'",
          ],
        ],
      ],
      'axis' => [
        'contains' => [
          'slotDuration' => [
            'default' => '',
          ],
          'slotLabelInterval' => [
            'default' => '',
          ],
          'slotLabelFormat' => [
            'default' => '',
          ],
          'minTime' => [
            'default' => '',
          ],
          'maxTime' => [
            'default' => '',
          ],
          'scrollTime' => [
            'default' => '',
          ],
        ],
      ],
      'nav' => [
        'contains' => [
          'defaultDate' => [
            'default' => '',
          ],
          'dateAlignment' => [
            'default' => '',
          ],
          'validRange' => [
            'default' => '',
          ],
        ],
      ],
      'links' => [
        'contains' => [
          'navLinks' => [
            'default' => 0,
          ],
          'navLinkDayClick' => [
            'default' => '',
          ],
          'navLinkWeekClick' => [
            'default' => '',
          ],
        ],
      ],
      'week' => [
        'contains' => [
          'weekNumbers' => [
            'default' => 0,
          ],
          'weekNumbersWithinDays' => [
            'default' => 0,
          ],
          'weekNumberCalculation' => [
            'default' => 'local',
          ],
          'weekLabel' => [
            'default' => 'W',
          ],
        ],
      ],
      'now' => [
        'contains' => [
          'nowIndicator' => [
            'default' => 0,
          ],
          'now' => [
            'default' => 0,
          ],
        ],
      ],
      'business' => [
        'contains' => [
          'businessHours' => [
            'default' => 0,
          ],
          'businessHours2' => [
            'default' => '',
          ],
        ],
      ],
      'style' => [
        'contains' => [
          'themeSystem' => [
            'default' => 'standard',
          ],
          'height' => [
            'default' => '',
          ],
          'contentHeight' => [
            'default' => '',
          ],
          'aspectRatio' => [
            'default' => '1.35',
          ],
          'handleWindowResize' => [
            'default' => 1,
          ],
          'windowResizeDelay' => [
            'default' => 100,
          ],
        ],
      ],
      'fields' => [
        'contains' => [
          'title' => [
            'default' => 0,
          ],
          'url' => [
            'default' => 0,
          ],
          'date' => [
            'default' => 0,
          ],
        ],
      ],
    ];
  }

  /**
   * Build a fieldset form element.
   *
   * @param string $title
   *   The title of the fieldset.
   * @param string $description
   *  The description.
   * @param bool $open
   *   If TRUE, the fieldset is open when the form loads.
   * @param string $fieldset
   *   The name of the parent fieldset.
   * @param array $states
   *   The FAPI states property.
   *
   * @return array
   *   Drupal FAPI array.
   */
  public function getFieldsetElement($title, $description = '', $open = FALSE, $fieldset = '', array $states = []) {
    $details = [
      '#type' => 'details',
      '#title' => $title,
      '#collapsible' => TRUE,
      '#open' => $open,
      '#prefix' => '<div class="clearfix" style="overflow: hidden;">',
      '#suffix' => '</div>',
    ];
    if ($description) {
      $details['#description'] = $description;
    }
    if ($fieldset) {
      $details['#fieldset'] = $fieldset;
    }
    if ($states) {
      $details['#states'] = $states;
    }
    return $details;
  }

  /**
   * Get a title format element.
   *
   * @param mixed $default
   *   The default value.
   * @param string $fieldset
   *   The name of the fieldset.
   * @param string $title
   *   The field title.
   *
   * @return array
   *   Drupal FAPI array.
   */
  public function getTitleFormatElement($default, $fieldset, $title = '') {
    return [
      '#type' => 'textfield',
      '#title' => !empty($title) ? $title : $this
        ->t('Title format'),
      '#description' => $this
        ->t("Determines the text that will be displayed in the header's title. Enter comma-separated key:value pairs for object properties e.g. year:'numeric', month:'long'. Each view has a specific default. This setting will set the value for all views.   @more-info", [
        '@more-info' => Link::fromTextAndUrl($this
          ->t('More info'), Url::fromUri(self::FC_DOCS_URL . '/titleFormat', [
          'attributes' => [
            'target' => '_blank',
          ],
        ]))
          ->toString(),
      ]),
      '#default_value' => $default,
      '#prefix' => '<div class="views-left-50">',
      '#suffix' => '</div>',
      '#size' => '60',
      '#fieldset' => $fieldset,
    ];
  }

  /**
   * Get a button text element.
   *
   * @param mixed $default
   *   The default value.
   * @param string $fieldset
   *   The name of the fieldset.
   * @param string $title
   *   The field title.
   *
   * @return array
   *   Drupal FAPI array.
   */
  public function getButtonTextElement($default, $fieldset, $title = '') {
    return [
      '#type' => 'textfield',
      '#title' => !empty($title) ? $title : $this
        ->t('Button text'),
      '#description' => $this
        ->t("Text that will be displayed on buttons of the header/footer. Use key:value pairs for view-specific formats e.g. buttonText: 'list day'. @more-info", [
        '@more-info' => Link::fromTextAndUrl($this
          ->t('More info'), Url::fromUri(self::FC_DOCS_URL . '/buttonText', [
          'attributes' => [
            'target' => '_blank',
          ],
        ]))
          ->toString(),
      ]),
      '#default_value' => $default,
      '#prefix' => '<div class="views-left-50">',
      '#suffix' => '</div>',
      '#size' => '60',
      '#fieldset' => $fieldset,
    ];
  }

  /**
   * Get a column header format element.
   *
   * @param mixed $default
   *   The default value.
   * @param string $fieldset
   *   The name of the fieldset.
   * @param string $title
   *   The field title.
   *
   * @return array
   *   Drupal FAPI array.
   */
  public function getColumnHeaderFormatElement($default, $fieldset, $title = '') {
    return [
      '#type' => 'textfield',
      '#title' => !empty($title) ? $title : t('Column header format'),
      '#description' => $this
        ->t('Determines the text that will be displayed the calendar’s column headings. Use comma-separated key:value pairs for @formatting properties e.g. weekday:short. @more-info', [
        '@formatting' => Link::fromTextAndUrl($this
          ->t('date-formatting object'), Url::fromUri(self::FC_DOCS_URL . '/date-formatting', [
          'attributes' => [
            'target' => '_blank',
          ],
        ]))
          ->toString(),
        '@more-info' => Link::fromTextAndUrl($this
          ->t('More info'), Url::fromUri(self::FC_DOCS_URL . '/columnHeaderFormat', [
          'attributes' => [
            'target' => '_blank',
          ],
        ]))
          ->toString(),
      ]),
      '#default_value' => $default,
      '#size' => '60',
      '#fieldset' => $fieldset,
    ];
  }

  /**
   * Get supported FC properties.
   *
   * @return array
   *   Associative array of array of properties keyed by the data type.
   */
  public function getCalendarProperties() {
    return [
      'scalar' => [
        'googleCalendarApiKey',
        'defaultView',
        'timeZone',
        'locale',
        'themeSystem',
        'firstDay',
        'weekends',
        'editable',
        'eventLimit',
        'businessHours',
        'weekNumbers',
        'weekNumbersWithinDays',
        'weekNumberCalculation',
        'weekLabel',
        'columnHeader',
        'defaultDate',
        'navLinks',
        'navLinkDayClick',
        'navLinkWeekClick',
        'scrollTime',
        'aspectRatio',
        'nowIndicator',
        'now',
        'slotDuration',
        'minTime',
        'maxTime',
        'titleRangeSeparator',
        'eventOverlap',
        'eventColor',
      ],
      'array' => [
        'hiddenDays',
      ],
      'object' => [
        'plugins',
        'validRange',
        'slotLabelFormat',
        'slotLabelInterval',
        'header',
        'footer',
        'buttonText',
      ],
    ];
  }

  /**
   * Check for valid Google Calendar API settings.
   *
   * @param $settings
   *
   * @return bool
   */
  public function isGoogleCalendar($settings) {
    return !empty($settings['google']['googleCalendarApiKey']) && !empty($settings['google']['googleCalendarId']);
  }

  /**
   * @todo: Review.
   * Flatten a multidimensional array.
   * @param array $array
   *   The input array.
   *
   * @return array
   *   The fllattened array.
   */
  public function flattenMultidimensionalArray($array) {
    $it = new RecursiveIteratorIterator(new RecursiveArrayIterator($array));
    return iterator_to_array($it, TRUE);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
OptionsFormHelperTrait::flattenMultidimensionalArray public function @todo: Review. Flatten a multidimensional array.
OptionsFormHelperTrait::getButtonTextElement public function Get a button text element.
OptionsFormHelperTrait::getCalendarProperties public function Get supported FC properties.
OptionsFormHelperTrait::getColumnHeaderFormatElement public function Get a column header format element.
OptionsFormHelperTrait::getDefaultOptions public function Get all FC default options that are supported.
OptionsFormHelperTrait::getFieldsetElement public function Build a fieldset form element.
OptionsFormHelperTrait::getTitleFormatElement public function Get a title format element.
OptionsFormHelperTrait::isGoogleCalendar public function Check for valid Google Calendar API settings.