You are here

class SlickFormatter in Slick Carousel 8.2

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

Provides Slick field formatters utilities.

Hierarchy

Expanded class hierarchy of SlickFormatter

1 string reference to 'SlickFormatter'
slick.services.yml in ./slick.services.yml
slick.services.yml
1 service uses SlickFormatter
slick.formatter in ./slick.services.yml
Drupal\slick\SlickFormatter

File

src/SlickFormatter.php, line 12

Namespace

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

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

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

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

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

    // Slick specific stuffs.
    $build['optionset'] = Slick::loadWithFallback($settings['optionset']);

    // Only display thumbnail nav if having at least 2 slides. This might be
    // an issue such as for ElevateZoom Plus module, but it should work it out.
    if (!isset($settings['nav'])) {
      $settings['nav'] = !empty($settings['optionset_thumbnail']) && isset($items[1]);
    }

    // Do not bother for SlickTextFormatter, or when vanilla is on.
    if (empty($settings['vanilla'])) {
      $build['optionset']
        ->whichLazy($settings);
    }
    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']);
    }
    $this
      ->getModuleHandler()
      ->alter('slick_settings', $build, $items);
  }

  /**
   * {@inheritdoc}
   */
  public function getThumbnail(array $settings = [], $item = NULL) {
    if (!empty($settings['uri'])) {
      return [
        '#theme' => 'image_style',
        '#style_name' => empty($settings['thumbnail_style']) ? 'thumbnail' : $settings['thumbnail_style'],
        '#uri' => $settings['uri'],
        '#item' => $item,
        '#alt' => $item && $item instanceof ImageItem ? $item
          ->getValue()['alt'] : '',
      ];
    }
    return [];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BlazyFormatter::$cropStyles protected property Returns available styles with crop in the effect name.
BlazyFormatter::$isCrop protected property Checks if the image style contains crop in the effect name.
BlazyFormatter::$isImageDimensionSet private property Checks if image dimensions are set.
BlazyFormatter::cropStyles private function Returns available image styles with crop in the name.
BlazyFormatter::extractFirstItem public function Extract the first image item to build colorbox/zoom-like gallery. Overrides BlazyFormatterInterface::extractFirstItem
BlazyFormatter::isCrop public function Checks if an image style contains crop effect. Overrides BlazyFormatterInterface::isCrop
BlazyFormatter::postBuildElements public function Modifies the field formatter settings not inherited by child elements. Overrides BlazyFormatterInterface::postBuildElements
BlazyFormatter::setImageDimensions protected function Sets dimensions once to reduce method calls, if image style contains crop.
BlazyManager::backgroundImage private function Prepares CSS background image.
BlazyManager::build public function Returns the contents using theme_field(), or theme_item_list().
BlazyManager::buildCaption public function Build captions for both old image, or media entity.
BlazyManager::buildContent protected function Build out (rich media) content.
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::createPlaceholder protected function Build thumbnails, also to provide placeholder for blur effect.
BlazyManager::getBlazy public function Returns the enforced rich media content, or media using theme_blazy().
BlazyManager::getImage Deprecated public function Deprecated method.
BlazyManager::getSettings protected function Prepares Blazy settings.
BlazyManager::prepareBlazy protected function Prepares the Blazy output as a structured array ready for ::renderer().
BlazyManager::prepareBuild protected function Prepares Blazy outputs, extract items as indices.
BlazyManager::preRenderBlazy public function Builds the Blazy image as a structured array ready for ::renderer().
BlazyManager::preRenderBuild public function Builds the Blazy outputs as a structured array ready for ::renderer().
BlazyManager::thumbnailAndPlaceholder protected function Build thumbnails, also to provide placeholder for blur effect.
BlazyManager::trustedCallbacks public static function Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface::trustedCallbacks
BlazyManagerBase::$cache protected property The cache backend.
BlazyManagerBase::$configFactory protected property The config factory.
BlazyManagerBase::$entityRepository protected property The entity repository service.
BlazyManagerBase::$entityTypeManager protected property The entity type manager service.
BlazyManagerBase::$languageManager protected property The language manager.
BlazyManagerBase::$moduleHandler protected property The module handler service.
BlazyManagerBase::$renderer protected property The renderer.
BlazyManagerBase::$root protected property The app root.
BlazyManagerBase::attach public function Returns array of needed assets suitable for #attached property. Overrides BlazyManagerInterface::attach
BlazyManagerBase::buildSkins public function Collects defined skins as registered via hook_MODULE_NAME_skins_info().
BlazyManagerBase::configLoad public function Returns any config, or keyed by the $setting_name.
BlazyManagerBase::create public static function
BlazyManagerBase::entityLoad public function Returns a shortcut for loading a config entity: image_style, slick, etc.
BlazyManagerBase::entityLoadMultiple public function Returns a shortcut for loading multiple configuration entities.
BlazyManagerBase::getCache public function Returns the cache.
BlazyManagerBase::getCacheMetadata public function Return the cache metadata common for all blazy-related modules.
BlazyManagerBase::getCommonSettings public function Returns the common UI settings inherited down to each item.
BlazyManagerBase::getConfigFactory public function Returns the config factory.
BlazyManagerBase::getEntityRepository public function Returns the entity repository service.
BlazyManagerBase::getEntityTypeManager public function Returns the entity type manager.
BlazyManagerBase::getImageEffects public function Returns the supported image effects. Overrides BlazyManagerInterface::getImageEffects
BlazyManagerBase::getIoSettings public function Returns drupalSettings for IO. Overrides BlazyManagerInterface::getIoSettings
BlazyManagerBase::getLightboxes public function Gets the supported lightboxes. Overrides BlazyManagerInterface::getLightboxes
BlazyManagerBase::getModuleHandler public function Returns the module handler.
BlazyManagerBase::getRenderer public function Returns the renderer.
BlazyManagerBase::getResponsiveImageStyles public function Returns the Responsive image styles and caches tags.
BlazyManagerBase::isBlazy public function Checks for Blazy formatter such as from within a Views style plugin. Overrides BlazyManagerInterface::isBlazy
BlazyManagerBase::isBlazyFormatter protected function Collects the first found Blazy formatter settings within Views fields.
BlazyManagerBase::languageManager public function Returns the language manager service.
BlazyManagerBase::root public function Returns the app root.
BlazyManagerBase::setAttachments protected function Provides attachments and cache common for all blazy-related modules.
BlazyManagerBase::setLanguageManager public function Sets the language manager service.
BlazyManagerBase::setResponsiveImageDimensions public function Sets dimensions once to reduce method calls for Responsive image.
BlazyManagerBase::setRoot public function Sets app root service.
BlazyManagerBase::__construct public function Constructs a BlazyManager object.
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
SlickFormatter::buildSettings public function Modifies the field formatter settings inherited by child elements. Overrides BlazyFormatter::buildSettings
SlickFormatter::getThumbnail public function Gets the thumbnail image using theme_image_style(). Overrides SlickFormatterInterface::getThumbnail
SlickFormatter::preBuildElements public function Modifies the field formatter settings inherited by child elements. Overrides BlazyFormatter::preBuildElements
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.
TrustedCallbackInterface::THROW_EXCEPTION constant Untrusted callbacks throw exceptions.
TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION constant Untrusted callbacks trigger silenced E_USER_DEPRECATION errors.
TrustedCallbackInterface::TRIGGER_WARNING constant Untrusted callbacks trigger E_USER_WARNING errors.