You are here

public function ShortcodeCorrector::tips in Shortcode 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/ShortcodeCorrector.php, line 45

Class

ShortcodeCorrector
Filter that corrects html added by wysiwyg editors around shortcodes.

Namespace

Drupal\shortcode\Plugin\Filter

Code

public function tips($long = FALSE) {

  // Get enabled shortcodes for a specific text format.
  // Drupal 7 way:
  // $shortcodes = shortcode_list_all_enabled($format);
  // Drupal 8 way:

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

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

    /** @var \Drupal\shortcode\Plugin\ShortcodeInterface $shortcode */
    $shortcode = $type
      ->createInstance($plugin_id);
    $tips[] = $shortcode
      ->tips($long);
  }
  $output = '';
  foreach ($tips as $tip) {
    $output .= '<li>' . $tip . '</li>';
  }
  return '<p>You can use wp-like shortcodes such as: </p><ul>' . $output . '</ul>';
}