You are here

abstract class BlazyFormatterBase in Blazy 7

Base class for blazy-related modules (slick, etc.).

Defines one base class to extend for both image and file entity formatters.

Hierarchy

Expanded class hierarchy of BlazyFormatterBase

See also

Drupal\blazy\Plugin\Field\FieldFormatter\BlazyEntityBase

Drupal\blazy\Plugin\Field\FieldFormatter\BlazyImageFormatter

Drupal\blazy\Plugin\Field\FieldFormatter\BlazyFileFormatter

Drupal\slick\Plugin\Field\FieldFormatter\SlickImageFormatter

Drupal\slick\Plugin\Field\FieldFormatter\SlickFileFormatter

File

src/Plugin/Field/FieldFormatter/BlazyFormatterBase.php, line 18

Namespace

Drupal\blazy\Plugin\Field\FieldFormatter
View source
abstract class BlazyFormatterBase extends FormatterBase {

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

  /**
   * Returns the blazy admin service for blazy-related module.
   */
  public abstract function admin();

  /**
   * {@inheritdoc}
   */
  public function settingsForm($form, &$form_state, $definition) {
    parent::settingsForm($form, $form_state, $definition);
    $element = [];
    $definition['_views'] = isset($form['field_api_classes']);
    $this
      ->admin()
      ->buildSettingsForm($element, $definition);
    return $element;
  }

  /**
   * {@inheritdoc}
   */
  public function getRequiredForms() {
    return [
      'grid' => $this->isMultiple,
      'image_style' => TRUE,
      'media_switch' => TRUE,
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getScopedFormElements() {
    return [
      'background' => TRUE,
      'breakpoints' => BlazyDefault::getConstantBreakpoints(),
      'box_captions' => TRUE,
      'namespace' => 'blazy',
      'style' => $this->isMultiple,
      'thumbnail_style' => TRUE,
      'captions' => [
        'title' => t('Title'),
        'alt' => t('Alt'),
      ],
    ] + parent::getScopedFormElements();
  }

  /**
   * Converts $items array to object for easy D8 -> D7 backports.
   *
   * When extending this class, be sure to override this as needed as $items
   * can be just anything. This one assumes image, or file entity.
   * The actual D8 method is now taken care of at image_field_prepare_view().
   * At D7, image is not an entity, of course, bear the method name.
   *
   * @see \Drupal\blazy\BlazyEntityBase
   */
  protected function getEntitiesToView($items) {
    if (empty($items)) {
      return [];
    }
    $files = [];
    foreach ($items as $item) {
      $file = is_object($item) ? $item : (object) $item;
      $file->targetType = 'file';
      $files[] = $file;
    }
    return $files;
  }

  /**
   * Build individual item if so configured such as for file entity goodness.
   */
  public abstract function buildElement(array &$element, $entity, $delta = 0);

  /**
   * {@inheritdoc}
   */
  public function settingsSummary(array $definition) {
    return $this
      ->admin()
      ->getSettingsSummary($definition);
  }

}

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::defaultSettings public static function Returns default settings. Overrides FormatterBase::defaultSettings 1
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::getScopedFormElements public function Defines the scope for the form elements. Overrides FormatterBase::getScopedFormElements 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
FormatterBase::__construct public function Constructs a base formatter object. 2