public function Freelinking::tips in Freelinking 8.3
Same name and namespace in other branches
- 4.0.x src/Plugin/Filter/Freelinking.php \Drupal\freelinking\Plugin\Filter\Freelinking::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/ Freelinking.php, line 157
Class
- Freelinking
- Freelinking input filter plugin.
Namespace
Drupal\freelinking\Plugin\FilterCode
public function tips($long = FALSE) {
$text = $this
->t('Freelinking helps you easily create HTML links. Links take the form of <code>[[indicator:target|Title]].</code>');
if (!$long) {
if (isset($this->settings['default']) && 'NONE' !== $this->settings['default']) {
$plugin = $this->freelinkingManager
->createInstance($this->settings['default']);
$text .= ' ' . $plugin
->getTip();
}
return $text;
}
$content = <<<EOF
<p>Freelinking helps you easily create HTML links. Links take the form of <code>[[indicator:target|Title]].</code><br />
Below is a list of available types of freelinks you may use, organized as <strong>Plugin Name</strong>: [<em>indicator</em>].</p>
<ul>
EOF;
// Assemble tips for each allowed plugin.
$allowed_plugins = $this
->extractAllowedPlugins($this->settings['plugins']);
foreach ($allowed_plugins as $plugin_name => $plugin_info) {
$settings = isset($plugin_info['settings']) ? $plugin_info['settings'] : [];
$plugin = $this->freelinkingManager
->createInstance($plugin_info['plugin'], $settings);
$content .= '<li><strong>' . $plugin
->getPluginDefinition()['title'] . '</strong> [<em>' . $plugin
->getIndicator() . '</em>]: ' . $plugin
->getTip() . '</li>';
}
$content .= '</ul>';
// Ignore phpcs warning because tips are dynamically generated based on
// plugins. This follows the pattern in core.
// @see \Drupal\filter\Plugin\Filter\FilterAlign::tips().
return $this
->t($content);
}