You are here

public function LazyFilter::tips in Lazy-load 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/Filter/LazyFilter.php \Drupal\lazy\Plugin\Filter\LazyFilter::tips()
  2. 8 src/Plugin/Filter/LazyFilter.php \Drupal\lazy\Plugin\Filter\LazyFilter::tips()

Generates a filter's tip.

A filter's tips should be informative and to the point. Short tips are preferably one-liners.

@todo Split into getSummaryItem() and buildGuidelines().

Parameters

bool $long: Whether this callback should return a short tip to display in a form (FALSE), or whether a more elaborate filter tips should be returned for template_preprocess_filter_tips() (TRUE).

Return value

string|null Translated text to display as a tip, or NULL if this filter has no tip.

Overrides FilterBase::tips

File

src/Plugin/Filter/LazyFilter.php, line 83

Class

LazyFilter
Provides a filter to lazy-load images.

Namespace

Drupal\lazy\Plugin\Filter

Code

public function tips($long = FALSE) {
  $settings = \Drupal::config('lazy.settings');
  $tags = $settings
    ->get('alter_tag');
  $skip = $settings
    ->get('skipClass');
  $options = [
    '%img' => '<img>',
    '%iframe' => '<iframe>',
  ];
  $skip_help = t('If you want certain elements skip lazy-loading, add <code>%class</code> class name.', [
    '%class' => $skip,
  ]);
  if (!empty($tags)) {
    if ($tags['img'] && $tags['iframe']) {
      return t('Lazy-loading is enabled for both %img and %iframe tags.', $options) . ' ' . $skip_help;
    }
    elseif ($tags['img']) {
      return t('Lazy-loading is enabled for %img tags.', $options) . ' ' . $skip_help;
    }
    elseif ($tags['iframe']) {
      return t('Lazy-loading is enabled for %iframe tags.', $options) . ' ' . $skip_help;
    }
  }
  return t('Lazy-loading is not enabled.');
}