You are here

public function BaseParser::tips in Markdown 3.0.x

Generates a filter's tip.

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

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 MarkdownParserInterface::tips

File

src/Plugin/Markdown/BaseParser.php, line 451

Class

BaseParser
Plugin annotation @MarkdownParser( id = "_broken", label = @Translation("Missing Parser"), )

Namespace

Drupal\markdown\Plugin\Markdown

Code

public function tips($long = FALSE) {

  // On the "short" tips, just show and render the summary, if any.
  if (!$long) {
    $summary = $this
      ->getSummary();
    if (!$summary) {
      return NULL;
    }
    return (string) \Drupal::service('renderer')
      ->render($summary);
  }

  // On the long tips, the render array must be retrieved as a "form" due to
  // the fact that vertical tabs require form processing to work properly.
  $formBuilder = \Drupal::formBuilder();
  $formState = (new FormState())
    ->addBuildInfo('args', [
    $long,
    $this,
  ]);
  $form = $formBuilder
    ->buildForm('\\Drupal\\markdown\\Form\\MarkdownFilterTipsForm', $formState);

  // Since this is essentially "hacking" the FAPI and not an actual "form",
  // just extract the relevant child elements from the "form" and render it.
  $tips = [];
  foreach ([
    'help',
    'tips',
    'guides',
    'allowed_tags',
  ] as $child) {
    if (isset($form[$child])) {
      $tips[] = $form[$child];
    }
  }
  return \Drupal::service('renderer')
    ->render($tips[1]);
}