You are here

public function Shortcode::tips in Shortcode 2.0.x

Same name and namespace in other branches
  1. 8 src/Plugin/Filter/Shortcode.php \Drupal\shortcode\Plugin\Filter\Shortcode::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/Shortcode.php, line 87

Class

Shortcode
Provides a filter for insert view.

Namespace

Drupal\shortcode\Plugin\Filter

Code

public function tips($long = FALSE) {

  /** @var \Drupal\shortcode\ShortcodeService $type */
  $type = \Drupal::service('shortcode');

  // todo: it duplicates the tips section.
  // Get enabled shortcodes for this text format.
  $shortcodes = $type
    ->getShortcodePlugins($this);

  /** @var \Drupal\shortcode\ShortcodePluginManager $type */
  $type = \Drupal::service('plugin.manager.shortcode');

  // Gather tips defined in all enabled plugins.
  $tips = [];
  foreach ($shortcodes as $shortcode_info) {

    /** @var \Drupal\shortcode\Plugin\ShortcodeInterface $shortcode */
    $shortcode = $type
      ->createInstance($shortcode_info['id']);
    $tips[] = $shortcode
      ->tips($long);
  }
  $output = '';
  foreach ($tips as $tip) {
    $output .= '<li>' . $tip . '</li>';
  }

  // todo: add render array instead of li/ul markup.
  // todo: add Translate markup.
  return '<p>You can use wp-like shortcodes such as: </p><ul>' . $output . '</ul>';
}