protected function CommerceAddToCartLinkViewsField::addSelfTokens in Commerce Add To Cart Link 8
Same name and namespace in other branches
- 2.x src/Plugin/views/field/CommerceAddToCartLinkViewsField.php \Drupal\commerce_add_to_cart_link\Plugin\views\field\CommerceAddToCartLinkViewsField::addSelfTokens()
Add any special tokens this field might use for itself.
This method is intended to be overridden by items that generate fields as a list. For example, the field that displays all terms on a node might have tokens for the tid and the term.
By convention, tokens should follow the format of {{ token__subtoken }} where token is the field ID and subtoken is the field. If the field ID is terms, then the tokens might be {{ terms__tid }} and {{ terms__name }}.
Overrides FieldPluginBase::addSelfTokens
File
- src/
Plugin/ views/ field/ CommerceAddToCartLinkViewsField.php, line 141
Class
- CommerceAddToCartLinkViewsField
- Defines a Views field that adds an add to cart link.
Namespace
Drupal\commerce_add_to_cart_link\Plugin\views\fieldCode
protected function addSelfTokens(&$tokens, $item) {
parent::addSelfTokens($tokens, $item);
/** @var \Drupal\Core\Url $url */
$url = $item['url'];
$tokens['{{ ' . $this->options['id'] . '__url' . ' }}'] = $url
->toString();
}