Issue #2903336 Added node context for tokens.
Adds token context array to url options array in database so that contextual tokens can validate on form submission.
a:1:{s:7:"context";a:1:{s:4:"node";s:3:"193";}}
This currently only works on form submissions, tested with a migration and it seems more work is needed to make this work in a migration, my assumption is that it probably won't work in other non-form related entity creations either. example JSON API
links are rendered correctly on the front end, but they are not tied to the context in the database, and are instead tied to the node itself.
The contrib module: https://www.drupal.org/project/field_group_link does not render link properly which leads to other questions about how these types of links should be rendered.
Additionally, this does not account for entity references via token.
Merge request reports
Activity
changed title from Added node context for tokens. to Added node context for tokens.{+ https://www.drupal.org/project/drupal/issues/2903336+}
32 32 */ 33 33 public function isExternal(); 34 34 35 /** 36 * Determines if a link is a token. 37 * 38 * @return bool 39 * TRUE if the link is external, FALSE otherwise. changed this line in version 2 of the diff
added 1 commit
- 8be3cf0c - Fixing coding standard errors https://www.drupal.org/pift-ci-job/2152033
399 408 * {@inheritdoc} 400 409 */ 401 410 public function massageFormValues(array $values, array $form, FormStateInterface $form_state) { 411 $entity = $form_state->getFormObject()->getEntity(); 402 412 foreach ($values as &$value) { 403 413 $value['uri'] = static::getUserEnteredStringAsUri($value['uri']); 414 404 415 $value += ['options' => []]; 416 $value['options']['context'] = [ - Comment on lines 409 to +416
- Resolved by Chris Green
- Resolved by Chris Green
462 481 } 463 482 483 /** 484 * Creates a new Url from token. 485 * 486 * @param string $uri 487 * The original passed in URI. 488 * @param array $options 489 * An array of options, see \Drupal\Core\Url::fromUri() for details. 490 * 491 * @return \Drupal\Core\Url 492 * A new Url object for a 'token:' URI. 493 */ 494 protected static function fromToken($uri, array $options) { 495 $token_string = ltrim($uri, 'token:'); 496 $token_service = \Drupal::token(); - Resolved by Chris Green
32 32 */ 33 33 public function isExternal(); 34 34 35 /** 36 * Determines if a link is a token. 37 * 38 * @return bool 39 * TRUE if the link contains a token, FALSE otherwise. 40 */ 41 public function isToken(); 42 added 1 commit
- 840a1d98 - Changed the token replace with replacePlain function