You are here

public function TipPluginBase::getAttributes in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/tour/src/TipPluginBase.php \Drupal\tour\TipPluginBase::getAttributes()

@todo remove in https://drupal.org/node/3195193

Overrides TipPluginInterface::getAttributes

1 call to TipPluginBase::getAttributes()
TipPluginTextLegacy::getAttributes in core/modules/tour/tests/tour_test/src/Plugin/tour/tip/TipPluginTextLegacy.php
@todo remove in https://drupal.org/node/3195193
1 method overrides TipPluginBase::getAttributes()
TipPluginTextLegacy::getAttributes in core/modules/tour/tests/tour_test/src/Plugin/tour/tip/TipPluginTextLegacy.php
@todo remove in https://drupal.org/node/3195193

File

core/modules/tour/src/TipPluginBase.php, line 79

Class

TipPluginBase
Defines a base tour item implementation.

Namespace

Drupal\tour

Code

public function getAttributes() {

  // This method is deprecated and rewritten to be as backwards compatible as
  // possible with pre-existing uses. Due to the flexibility of tip plugins,
  // this backwards compatibility can't be fully guaranteed. Because of this,
  // we trigger a warning to caution the use of this function. This warning
  // does not stop page execution, but will be logged.
  trigger_error(__NAMESPACE__ . '\\TipPluginInterface::getAttributes is deprecated. Tour tip plugins should implement ' . __NAMESPACE__ . '\\TourTipPluginInterface and Tour configs should use the \'selector\' property instead of \'attributes\' to target an element.', E_USER_WARNING);

  // The _tour_update_joyride() updates the deprecated 'attributes' property
  // to the current 'selector' property. It's possible that additional
  // attributes not supported by Drupal core exist and these need to merged
  // in.
  $attributes = $this
    ->get('attributes') ?: [];

  // Convert the selector property to the expected structure.
  $selector = $this
    ->get('selector');
  $first_char = substr($selector, 0, 1);
  if ($first_char === '#') {
    $attributes['data-id'] = substr($selector, 1);
  }
  elseif ($first_char === '.') {
    $attributes['data-class'] = substr($selector, 1);
  }
  return $attributes;
}