Skip to content
Snippets Groups Projects

Issue #2903336 Added node context for tokens.

Open Issue #2903336 Added node context for tokens.
5 unresolved threads
Open Chris Green requested to merge issue/drupal-2903336:9.2.x into 11.x
5 unresolved threads

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.

Edited by Chris Green

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
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.
  • Chris Green added 1 commit

    added 1 commit

    • 9b9a8049 - removing ['target'] = 'custom_uri';

    Compare with previous version

  • 399 408 * {@inheritdoc}
    400 409 */
  • 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'] = [
  • 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();
  • Chris Green added 1 commit

    added 1 commit

    • b6f77fb5 - Apply 1 suggestion(s) to 1 file(s)

    Compare with previous version

  • Chris Green added 1 commit

    added 1 commit

    • 6dafb7ce - Apply 1 suggestion(s) to 1 file(s)

    Compare with previous version

  • Chris Green added 1 commit

    added 1 commit

    • da7309fb - Apply 1 suggestion(s) to 1 file(s)

    Compare with previous version

  • 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
  • Oleh Shevchuk added 1 commit

    added 1 commit

    • 840a1d98 - Changed the token replace with replacePlain function

    Compare with previous version

  • Please register or sign in to reply
    Loading