You are here

public function VideoFilter::tips in Video Filter 8

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/VideoFilter.php, line 250

Class

VideoFilter
Render Video Filter.

Namespace

Drupal\video_filter\Plugin\Filter

Code

public function tips($long = FALSE) {

  // Show long description.
  if ($long) {
    $tips = [];
    $supported = [];
    foreach (array_filter($this->settings['plugins']) as $plugin_id) {
      $plugin = $this->plugin_manager
        ->createInstance($plugin_id);

      // Get plugin/codec usage instructions.
      $instructions = $plugin
        ->instructions();
      $supported[] = '<strong>' . $plugin
        ->getName() . '</strong>';
      if (!empty($instructions)) {
        $tips[] = $instructions;
      }
    }
    return $this
      ->t('
        <p><strong>Video Filter</strong></p>
        <p>You may insert videos from popular video sites by using a simple tag <code>[video:URL]</code>.</p>
        <p>Examples:</p>
        <ul>
          <li>Single video:<br /><code>[video:http://www.youtube.com/watch?v=uN1qUeId]</code></li>
          <li>Random video out of multiple:<br /><code>[video:http://www.youtube.com/watch?v=uN1qUeId1,http://www.youtube.com/watch?v=uN1qUeId2]</code></li>
          <li>Override default autoplay setting: <code>[video:http://www.youtube.com/watch?v=uN1qUeId autoplay:1]</code></li>
          <li>Override default width and height:<br /><code>[video:http://www.youtube.com/watch?v=uN1qUeId width:X height:Y]</code></li>
          <li>Override default aspect ratio:<br /><code>[video:http://www.youtube.com/watch?v=uN1qUeId ratio:4/3]</code></li>
          <li>Align the video:<br /><code>[video:http://www.youtube.com/watch?v=uN1qUeId align:right]</code></li>
        </ul>
        <p>Supported sites: !codecs.</p>
        <p><strong>Special instructions:</strong></p>
        <p><em>Some codecs need special input. You\'ll find those instructions here.</em></p>
        <ul>!instructions</ul>', [
      '!codecs' => implode(', ', $supported),
      '!instructions' => implode('', $tips),
    ]);
  }
  else {
    return $this
      ->t('You may insert videos with [video:URL]');
  }
}