You are here

abstract class SlickFormatterBase in Slick Carousel 7.3

Base class for slick image and file entity (Media) formatters.

Hierarchy

Expanded class hierarchy of SlickFormatterBase

See also

Drupal\slick\Plugin\Field\SlickFileFormatter

Drupal\slick\Plugin\Field\SlickImageFormatter

File

src/Plugin/Field/FieldFormatter/SlickFormatterBase.php, line 16

Namespace

Drupal\slick\Plugin\Field\FieldFormatter
View source
abstract class SlickFormatterBase extends BlazyFormatterBase {

  /**
   * Constructs a SlickImageFormatter instance.
   */
  public function __construct($plugin_id, $field, $instance, SlickFormatterInterface $formatter, SlickManagerInterface $manager) {
    parent::__construct($plugin_id, $field, $instance);
    $this->formatter = $formatter;
    $this->manager = $manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function defaultSettings() {
    return SlickDefault::imageSettings();
  }

  /**
   * Build the slick carousel elements.
   */
  public function buildElements(array &$build, $items) {
    $settings = $build['settings'];
    $item_id = $settings['item_id'];
    foreach ($items as $delta => $item) {
      $settings['delta'] = $delta;
      $settings['type'] = isset($item->type) ? $item->type : 'image';
      $settings['uri'] = $item->uri;
      $element = [
        'item' => $item,
        'settings' => $settings,
        'content' => [],
      ];

      // Provide advanced functionality to build fieldable elements.
      $this
        ->buildElement($element, $item, $delta);

      // Build individual slick item.
      $build['items'][$delta] = $element;

      // Build individual slick thumbnail.
      if (!empty($settings['nav'])) {
        $thumb = [
          'settings' => $element['settings'],
        ];

        // Thumbnail usages: asNavFor pagers, dot, arrows, photobox thumbnails.
        $thumb[$item_id] = empty($settings['thumbnail_style']) ? [] : $this
          ->formatter()
          ->getThumbnail($element['settings'], $element['item']);
        $thumb['caption'] = empty($settings['thumbnail_caption']) ? [] : array_filter($this
          ->getCaption($item, $settings['thumbnail_caption'], $settings));
        $build['thumb']['items'][$delta] = $thumb;
      }
    }
  }

  /**
   * Build caption element if so configured can be used for thumbnail caption.
   */
  protected abstract function getCaption($entity, $field_name, $settings);

  /**
   * {@inheritdoc}
   */
  public function getScopedFormElements() {
    return [
      'namespace' => 'slick',
      'nav' => TRUE,
      'thumb_captions' => [
        'title' => t('Title'),
        'alt' => t('Alt'),
      ],
      'thumb_positions' => TRUE,
    ] + parent::getScopedFormElements();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BlazyFormatterBase::admin abstract public function Returns the blazy admin service for blazy-related module. 1
BlazyFormatterBase::buildElement abstract public function Build individual item if so configured such as for file entity goodness. 2
BlazyFormatterBase::getEntitiesToView protected function Converts $items array to object for easy D8 -> D7 backports. 1
BlazyFormatterBase::getRequiredForms public function Returns required form elements for the current formatter. Overrides FormatterBase::getRequiredForms 2
BlazyFormatterBase::settingsForm public function Implements hook_field_formatter_settings_form(). Overrides FormatterBase::settingsForm 1
BlazyFormatterBase::settingsSummary public function Implements hook_field_formatter_settings_summary(). Overrides FormatterBase::settingsSummary
FormatterBase::$admin protected property The blazy-related admin formatter service.
FormatterBase::$defaultSettingsMerged protected property Whether default settings have been merged into the current $settings.
FormatterBase::$fieldDefinition protected property The field definition.
FormatterBase::$fieldDisplay protected property The field display.
FormatterBase::$fieldInstance protected property The field instance.
FormatterBase::$htmlSettings protected property The form settings.
FormatterBase::$isMultiple protected property True if the field cardinality equals -1.
FormatterBase::$knownEntities protected property The known hard-coded entities.
FormatterBase::$langcode protected property The langcode.
FormatterBase::$pluginId protected property The blazy formatter plugin id.
FormatterBase::$settings protected property The formatter settings.
FormatterBase::$viewMode protected property The view mode.
FormatterBase::buildSettings public function Builds the settings. 1
FormatterBase::buildSettingsForm public function Implements hook_field_formatter_settings_form().
FormatterBase::buildSettingsSummary public function
FormatterBase::getHtmlSettings public function Gets html settings.
FormatterBase::getPluginId public function Gets formatter plugin id.
FormatterBase::getSetting public function
FormatterBase::getSettings public function Gets formatter settings.
FormatterBase::mergeDefaults protected function Merges default settings values into $settings.
FormatterBase::setHtmlSettings public function Sets html settings.
FormatterBase::setSetting public function
FormatterBase::setSettings public function Sets formatter settings.
FormatterBase::setupFieldVariables protected function Setup common variables across different hooks.
FormatterBase::view public function Implements hook_field_formatter_view().
FormatterBase::viewElements abstract public function Implements hook_field_formatter_view(). Overrides FormatterInterface::viewElements 2
SlickFormatterBase::buildElements public function Build the slick carousel elements. 1
SlickFormatterBase::defaultSettings public static function Returns default settings. Overrides BlazyFormatterBase::defaultSettings 1
SlickFormatterBase::getCaption abstract protected function Build caption element if so configured can be used for thumbnail caption. 2
SlickFormatterBase::getScopedFormElements public function Defines the scope for the form elements. Overrides BlazyFormatterBase::getScopedFormElements 1
SlickFormatterBase::__construct public function Constructs a SlickImageFormatter instance. Overrides FormatterBase::__construct