You are here

AddToCalendarWidgetType.php in Add To Calendar Button (AddEvent.com) 8.3

Same filename and directory in other branches
  1. 8.4 src/Plugin/Field/FieldWidget/AddToCalendarWidgetType.php

File

src/Plugin/Field/FieldWidget/AddToCalendarWidgetType.php
View source
<?php

namespace Drupal\addtocalendar\Plugin\Field\FieldWidget;

use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface;

/**
 * Plugin implementation of the 'example_widget_type' widget.
 *
 * @FieldWidget(
 *   id = "add_to_calendar_widget_type",
 *   label = @Translation("Add to calendar widget type"),
 *   field_types = {
 *     "add_to_calendar_field"
 *   }
 * )
 */
class AddToCalendarWidgetType extends WidgetBase {

  /**
   * {@inheritdoc}
   */
  public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
    $element['value'] = $element + [
      '#type' => 'checkbox',
      '#default_value' => !empty($items[0]->value),
    ];
    $element['value']['#title'] = 'Show add to calendar widget';
    $element['value']['#title_display'] = 'after';
    return $element;
  }

}

Classes

Namesort descending Description
AddToCalendarWidgetType Plugin implementation of the 'example_widget_type' widget.