class TipPluginText

Displays some text as a tip.

Plugin annotation

@Tip("text");

Hierarchy

Expanded class hierarchy of TipPluginText

File

drupal/core/modules/tour/lib/Drupal/tour/Plugin/tour/tip/TipPluginText.php, line 18
Contains \Drupal\tour\Plugin\tour\tip\TipPluginText.

Namespace

Drupal\tour\Plugin\tour\tip
View source
class TipPluginText extends TipPluginBase {

  /**
   * The body text which is used for render of this Text Tip.
   *
   * @var string
   */
  protected $body;

  /**
   * The forced position of where the tip will be located.
   *
   * @var string
   */
  protected $location;

  /**
   * Returns a ID that is guaranteed uniqueness.
   *
   * @return string
   *   A unique id to be used to generate aria attributes.
   */
  public function getAriaId() {
    static $id;
    if (!isset($id)) {
      $id = drupal_html_id($this
        ->get('id'));
    }
    return $id;
  }

  /**
   * Returns body of the text tip.
   *
   * @return string
   *   The tip body.
   */
  public function getBody() {
    return $this
      ->get('body');
  }

  /**
   * Returns location of the text tip.
   *
   * @return string
   *   The tip location.
   */
  public function getLocation() {
    return $this
      ->get('location');
  }

  /**
   * Overrides \Drupal\tour\TipPluginBase::getAttributes().
   */
  public function getAttributes() {
    $attributes = parent::getAttributes();
    $attributes['data-aria-describedby'] = 'tour-tip-' . $this
      ->getAriaId() . '-contents';
    $attributes['data-aria-labelledby'] = 'tour-tip-' . $this
      ->getAriaId() . '-label';
    if ($location = $this
      ->get('location')) {
      $attributes['data-options'] = 'tipLocation:' . $location;
    }
    return $attributes;
  }

  /**
   * Implements \Drupal\tour\TipPluginInterface::getOutput().
   */
  public function getOutput() {
    $output = '<h2 class="tour-tip-label" id="tour-tip-' . $this
      ->getAriaId() . '-label">' . check_plain($this
      ->getLabel()) . '</h2>';
    $output .= '<p class="tour-tip-body" id="tour-tip-' . $this
      ->getAriaId() . '-contents">' . filter_xss_admin($this
      ->getBody()) . '</p>';
    return array(
      '#markup' => $output,
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition.
PluginBase::$pluginId protected property The plugin_id.
PluginBase::getPluginDefinition public function Returns the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition
PluginBase::getPluginId public function Returns the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::__construct public function Constructs a Drupal\Component\Plugin\PluginBase object. 17
TipPluginBase::$attributes protected property The attributes that will be applied to the markup of this tip.
TipPluginBase::$label protected property The label which is used for render of this tip.
TipPluginBase::$weight protected property Allows tips to take more priority that others.
TipPluginBase::get public function Implements \Drupal\tour\TipPluginInterface::get(). Overrides TipPluginInterface::get
TipPluginBase::getLabel public function Implements \Drupal\tour\TipPluginInterface::getLabel(). Overrides TipPluginInterface::getLabel
TipPluginBase::getWeight public function Implements \Drupal\tour\TipPluginInterface::getWeight(). Overrides TipPluginInterface::getWeight
TipPluginBase::set public function Implements \Drupal\tour\TipPluginInterface::set(). Overrides TipPluginInterface::set
TipPluginText::$body protected property The body text which is used for render of this Text Tip.
TipPluginText::$location protected property The forced position of where the tip will be located.
TipPluginText::getAriaId public function Returns a ID that is guaranteed uniqueness.
TipPluginText::getAttributes public function Overrides \Drupal\tour\TipPluginBase::getAttributes(). Overrides TipPluginBase::getAttributes
TipPluginText::getBody public function Returns body of the text tip.
TipPluginText::getLocation public function Returns location of the text tip.
TipPluginText::getOutput public function Implements \Drupal\tour\TipPluginInterface::getOutput(). Overrides TipPluginInterface::getOutput