You are here

class BatStateWidget in Booking and Availability Management Tools for Drupal 8

Plugin annotation


@FacetsWidget(
  id = "bat_state",
  label = @Translation("BAT State"),
  description = @Translation("A configurable widget for BAT"),
)

Hierarchy

Expanded class hierarchy of BatStateWidget

File

modules/bat_facets/src/Plugin/facets/widget/BatStateWidget.php, line 22
Contains \Drupal\bat_facets\Plugin\facets\widget\BatStateWidget.

Namespace

Drupal\bat_facets\Plugin\facets\widget
View source
class BatStateWidget extends LinksWidget {

  /**
   * The form builder.
   *
   * @var \Drupal\Core\Form\FormBuilder
   */
  protected $formBuilder;

  /**
   * {@inheritdoc}
   */
  public function build(FacetInterface $facet) {
    $build = $this->formBuilder
      ->getForm('Drupal\\bat_facets\\Form\\FacetsAvailabilityForm');
    return $build;
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet) {
    $event_types_options = [];
    $event_types = bat_event_get_types();
    foreach ($event_types as $event_type) {
      $event_types_options[$event_type
        ->id()] = $event_type
        ->label();
    }
    if (isset($this
      ->getConfiguration()['event_type'])) {
      $ev_type = $this
        ->getConfiguration()['event_type'];
    }
    else {
      $ev_types = array_keys($event_types_options);
      $ev_type = reset($ev_types);
    }
    $form['event_type'] = [
      '#type' => 'select',
      '#title' => t('Event type'),
      '#options' => $event_types_options,
      '#default_value' => $ev_type,
      '#ajax' => [
        'callback' => '::buildAjaxWidgetConfigForm',
        'wrapper' => 'facets-widget-config-form',
      ],
    ];
    if ($event_types[$ev_type]
      ->getFixedEventStates()) {
      $state_options = bat_unit_state_options($ev_type);
      $form['state'] = [
        '#type' => 'select',
        '#title' => t('Event State'),
        '#options' => $state_options,
        '#multiple' => TRUE,
        '#default_value' => isset($this
          ->getConfiguration()['state']) ? $this
          ->getConfiguration()['state'] : '',
      ];
    }
    else {
      $form['first_state'] = [
        '#type' => 'textfield',
        '#title' => t('First state'),
        '#size' => 10,
        '#prefix' => '<div class="container-inline">',
        '#default_value' => isset($this
          ->getConfiguration()['first_state']) ? $this
          ->getConfiguration()['first_state'] : '',
      ];
      $form['second_state'] = [
        '#type' => 'textfield',
        '#title' => t('Second state'),
        '#size' => 10,
        '#suffix' => '</div>',
        '#default_value' => isset($this
          ->getConfiguration()['second_state']) ? $this
          ->getConfiguration()['second_state'] : '',
      ];
    }
    return $form;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BatStateWidget::$formBuilder protected property The form builder.
BatStateWidget::build public function Builds the facet widget for rendering. Overrides LinksWidget::build
BatStateWidget::buildConfigurationForm public function Provides a configuration form for this widget. Overrides LinksWidget::buildConfigurationForm
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
LinksWidget::appendWidgetLibrary protected function Appends widget library and relevant information for it to build array. 1
LinksWidget::defaultConfiguration public function Gets default configuration for this plugin. Overrides WidgetPluginBase::defaultConfiguration
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
WidgetPluginBase::$facet protected property The facet the widget is being built for.
WidgetPluginBase::$showNumbers protected property Show the amount of results next to the result.
WidgetPluginBase::buildListItems protected function Builds a renderable array of result items. 1
WidgetPluginBase::buildResultItem protected function Builds a facet result item.
WidgetPluginBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies
WidgetPluginBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
WidgetPluginBase::getFacetItemListThemeHook protected function Provides a full array of possible theme functions to try for a given hook.
WidgetPluginBase::getQueryType public function Picks the preferred query type for this widget. Overrides WidgetPluginInterface::getQueryType 3
WidgetPluginBase::isPropertyRequired public function Checks is a specific property is required for this widget. Overrides WidgetPluginInterface::isPropertyRequired 2
WidgetPluginBase::prepareLink protected function Returns the text or link for an item.
WidgetPluginBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
WidgetPluginBase::supportsFacet public function Checks if the facet is supported by this processor. Overrides WidgetPluginInterface::supportsFacet 1
WidgetPluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct