You are here

class SlickFormatter in Slick Carousel 7.3

Same name and namespace in other branches
  1. 8.2 src/SlickFormatter.php \Drupal\slick\SlickFormatter
  2. 8 src/SlickFormatter.php \Drupal\slick\SlickFormatter

Implements SlickFormatterInterface.

Hierarchy

Expanded class hierarchy of SlickFormatter

1 file declares its use of SlickFormatter
slick.module in ./slick.module
Slick carousel integration, the last carousel you'll ever need.

File

src/SlickFormatter.php, line 11

Namespace

Drupal\slick
View source
class SlickFormatter extends BlazyFormatter implements SlickFormatterInterface {

  /**
   * {@inheritdoc}
   */
  public function buildSettings(array &$build, $items, $entity) {
    $settings =& $build['settings'];

    // Prepare integration with Blazy.
    $settings['item_id'] = 'slide';
    $settings['namespace'] = 'slick';

    // Pass basic info to parent::buildSettings().
    parent::buildSettings($build, $items, $entity);
  }

  /**
   * {@inheritdoc}
   */
  public function preBuildElements(array &$build, $items, $entity, array $entities = []) {
    parent::preBuildElements($build, $items, $entity, $entities);
    $settings =& $build['settings'];

    // Load the optionset to work with.
    $optionset = Slick::loadWithFallback($settings['optionset']);

    // Defines settings which should reach container and down to each item here.
    $settings['nav'] = !empty($settings['optionset_thumbnail']) && isset($items[1]);

    // Do not bother for SlickTextFormatter, or when vanilla is on.
    if (empty($settings['vanilla'])) {
      $lazy = $optionset
        ->getSetting('lazyLoad');
      $settings['blazy'] = $lazy == 'blazy' || !empty($settings['blazy']);
      $settings['lazy'] = $settings['blazy'] ? 'blazy' : $lazy;
      if (empty($settings['blazy'])) {
        $settings['lazy_class'] = $settings['lazy_attribute'] = 'lazy';
      }
    }
    else {

      // Nothing to work with Vanilla on, disable the asnavfor, else JS error.
      $settings['nav'] = FALSE;
    }

    // Only trim overridables options if disabled.
    if (empty($settings['override']) && isset($settings['overridables'])) {
      $settings['overridables'] = array_filter($settings['overridables']);
    }
    $build['optionset'] = $optionset;
    drupal_alter('slick_settings', $build, $items);
  }

  /**
   * {@inheritdoc}
   */
  public function getThumbnail(array $settings = [], $item = NULL) {
    $thumbnail = [];
    $uri = empty($settings['thumbnail_uri']) ? $settings['uri'] : $settings['thumbnail_uri'];
    if (!empty($uri)) {
      $thumbnail = [
        '#theme' => 'image_style',
        '#style_name' => $settings['thumbnail_style'] ?: 'thumbnail',
        '#path' => $uri,
      ];

      // Extract relevant variables from image or file entity/ media.
      if ($item) {
        foreach ([
          'attributes',
          'height',
          'weight',
          'alt',
          'title',
        ] as $key) {

          // Do not output empty value to prevent ugly title undefined.
          if (isset($item->{$key})) {
            $thumbnail["#{$key}"] = $item->{$key};
          }
        }
      }
    }
    return $thumbnail;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BlazyFormatter::$firstItem protected property The first image item found.
BlazyFormatter::$isImageDimensionSet private property Checks if image dimensions are set.
BlazyFormatter::extractFirstItem public function
BlazyFormatter::postBuildElements public function
BlazyFormatter::setImageDimensions protected function Sets dimensions once to reduce method calls, if image style contains crop.
BlazyManager::build public function Returns the entire contents using theme_field(), or theme_item_list().
BlazyManager::buildCaption public function Build captions for both old image, or media entity.
BlazyManager::buildImage private function Build out image, or anything related, including cache, CSS background, etc.
BlazyManager::buildMedia private function Build out (Responsive) image.
BlazyManager::buildResponsiveImage private function Build out Responsive image.
BlazyManager::config public function Returns any config, or keyed by the $key. Overrides BlazyManagerBase::config
BlazyManager::createPlaceholder protected function Build thumbnails, also to provide placeholder for blur effect.
BlazyManager::getBlazy public function Returns the enforced content, or image using theme_blazy().
BlazyManager::prepareBuild protected function Prepares Blazy outputs, extract items, and returns updated $settings.
BlazyManager::prepareImage protected function Prepares the Blazy image as a structured array ready for ::renderer().
BlazyManager::preRender public function Builds the Blazy as a structured array ready for ::renderer().
BlazyManager::preRenderBuild public function Builds the Blazy outputs as a structured array ready for ::renderer().
BlazyManager::setAttachments private function Provides attachment and cache for both theme_field() and theme_item_list().
BlazyManager::thumbnailAndPlaceholder protected function Build thumbnails, also to provide placeholder for blur effect.
BlazyManager::typecast public function Typecast the needed settings, blazy-related module can override. Overrides BlazyManagerBase::typecast
BlazyManagerBase::$cropStyles private property Returns available styles with crop in the effect name.
BlazyManagerBase::$isCrop private property Checks if the image style contains crop in the effect name.
BlazyManagerBase::$isIoSettings protected property The blazy IO settings.
BlazyManagerBase::$optionsetOptions protected property The available optionsets for all blazy-related modules.
BlazyManagerBase::attach public function Returns array of needed assets suitable for #attached property. Overrides BlazyManagerInterface::attach
BlazyManagerBase::buildDataBlazy public function To be deprecated method.
BlazyManagerBase::buildSkins public function Collects defined skins as registered via hook_MODULE_NAME_skins_info().
BlazyManagerBase::cleanUpBreakpoints public function To be deprecated method.
BlazyManagerBase::cropStyles public function Returns available image styles with crop in the name.
BlazyManagerBase::getCacheId public function Returns the cache id based on few generic setting values.
BlazyManagerBase::getCommonSettings public function Returns the common settings inherited down to each item.
BlazyManagerBase::getImageEffects public function
BlazyManagerBase::getIoSettings public function Returns drupalSettings for IO.
BlazyManagerBase::getLightboxes public function Gets the supported lightboxes. Overrides BlazyManagerInterface::getLightboxes
BlazyManagerBase::getOptionsetOptions public function Returns available optionsets for select options.
BlazyManagerBase::isBlazy public function Checks for Blazy formatter such as from within a Views style plugin. Overrides BlazyManagerInterface::isBlazy
BlazyManagerBase::isCrop public function Checks if an image style contains crop effect.
SlickFormatter::buildSettings public function Overrides BlazyFormatter::buildSettings
SlickFormatter::getThumbnail public function Gets the thumbnail image using theme_image_style(). Overrides SlickFormatterInterface::getThumbnail
SlickFormatter::preBuildElements public function Overrides BlazyFormatter::preBuildElements