You are here

function _filter_tips in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/filter/filter.module \_filter_tips()
  2. 4 modules/filter.module \_filter_tips()
  3. 5 modules/filter/filter.module \_filter_tips()
  4. 6 modules/filter/filter.module \_filter_tips()
  5. 7 modules/filter/filter.module \_filter_tips()
  6. 10 core/modules/filter/filter.module \_filter_tips()

Retrieves the filter tips.

Parameters

string $format_id: The ID of the text format for which to retrieve tips, or -1 to return tips for all formats accessible to the current user.

bool $long: (optional) Boolean indicating whether the long form of tips should be returned. Defaults to FALSE.

Return value

array An associative array of filtering tips, keyed by filter name. Each filtering tip is an associative array with elements:

  • tip: Tip text.
  • id: Filter ID.
2 calls to _filter_tips()
FilterController::filterTips in core/modules/filter/src/Controller/FilterController.php
Displays a page with long filter tips.
template_preprocess_filter_guidelines in core/modules/filter/filter.module
Prepares variables for text format guideline templates.

File

core/modules/filter/filter.module, line 322
Framework for handling the filtering of content.

Code

function _filter_tips($format_id, $long = FALSE) {
  $formats = filter_formats(\Drupal::currentUser());
  $tips = [];

  // If only listing one format, extract it from the $formats array.
  if ($format_id != -1) {
    $formats = [
      $formats[$format_id],
    ];
  }
  foreach ($formats as $format) {
    foreach ($format
      ->filters() as $name => $filter) {
      if ($filter->status) {
        $tip = $filter
          ->tips($long);
        if (isset($tip)) {
          $tips[$format
            ->label()][$name] = [
            'tip' => [
              '#markup' => $tip,
            ],
            'id' => $name,
          ];
        }
      }
    }
  }
  return $tips;
}