toLink example

$form['#attached']['library'][] = 'media/form';

    return $form;
  }

  /** * {@inheritdoc} */
  public function save(array $form, FormStateInterface $form_state) {
    $saved = parent::save($form$form_state);
    $context = ['@type' => $this->entity->bundle(), '%label' => $this->entity->label(), 'link' => $this->entity->toLink($this->t('View'))->toString()];
    $logger = $this->logger('media');
    $t_args = ['@type' => $this->entity->bundle->entity->label(), '%label' => $this->entity->toLink($this->entity->label())->toString()];

    if ($saved === SAVED_NEW) {
      $logger->info('@type: added %label.', $context);
      $this->messenger()->addStatus($this->t('@type %label has been created.', $t_args));
    }
    else {
      $logger->info('@type: updated %label.', $context);
      $this->messenger()->addStatus($this->t('@type %label has been updated.', $t_args));
    }

    

  }

  /** * {@inheritdoc} */
  public function save(array $form, FormStateInterface $form_state) {
    $contact_form = $this->entity;
    $status = $contact_form->save();
    $contact_settings = $this->config('contact.settings');

    $edit_link = $this->entity->toLink($this->t('Edit'))->toString();
    $view_link = $contact_form->toLink($contact_form->label(), 'canonical')->toString();
    if ($status == SAVED_UPDATED) {
      $this->messenger()->addStatus($this->t('Contact form %label has been updated.', ['%label' => $view_link]));
      $this->logger('contact')->notice('Contact form %label has been updated.', ['%label' => $contact_form->label(), 'link' => $edit_link]);
    }
    else {
      $this->messenger()->addStatus($this->t('Contact form %label has been added.', ['%label' => $view_link]));
      $this->logger('contact')->notice('Contact form %label has been added.', ['%label' => $contact_form->label(), 'link' => $edit_link]);
    }

    // Update the default form.
'id' => $entity_id, 'label' => $entity_label, 'langcode' => 'es'],
      $entity_type_id,
    ]);

    $expected_link = Link::createFromRoute(
      $expected_text,
      $route_name,
      [$entity_type_id => $entity_id],
      ['entity_type' => $entity_type_id, 'entity' => $entity] + $link_options
    );

    $result_link = $entity->toLink($link_text$link_rel$link_options);
    $this->assertEquals($expected_link$result_link);
  }

  /** * Provides test data for testLink(). */
  public function providerTestLink() {
    $data = [];
    $data[] = [
      'some_entity_label',
      'qwerqwer',
      
parent::flagViolations($violations$form$form_state);
  }

  /** * {@inheritdoc} */
  public function save(array $form, FormStateInterface $form_state) {
    $term = $this->entity;

    $result = $term->save();

    $edit_link = $term->toLink($this->t('Edit'), 'edit-form')->toString();
    $view_link = $term->toLink()->toString();
    switch ($result) {
      case SAVED_NEW:
        $this->messenger()->addStatus($this->t('Created new term %term.', ['%term' => $view_link]));
        $this->logger('taxonomy')->notice('Created new term %term.', ['%term' => $term->getName(), 'link' => $edit_link]);
        break;

      case SAVED_UPDATED:
        $this->messenger()->addStatus($this->t('Updated term %term.', ['%term' => $view_link]));
        $this->logger('taxonomy')->notice('Updated term %term.', ['%term' => $term->getName(), 'link' => $edit_link]);
        $form_state->setRedirect('entity.taxonomy_term.canonical', ['taxonomy_term' => $term->id()]);
        

  protected function nodeTitleList(array $nids$title) {
    $nodes = $this->entityTypeManager->getStorage('node')->loadMultiple($nids);

    $items = [];
    foreach ($nids as $nid) {
      $node = $this->entityRepository->getTranslationFromContext($nodes[$nid]);
      $item = $node->toLink()->toRenderable();
      $this->renderer->addCacheableDependency($item$node);
      $items[] = $item;
    }

    return [
      '#theme' => 'item_list__node',
      '#items' => $items,
      '#title' => $title,
      '#cache' => [
        'tags' => $this->entityTypeManager->getDefinition('node')->getListCacheTags(),
      ],
    ];

    $form_state->setRedirect('entity.node.preview', $route_parameters$options);
  }

  /** * {@inheritdoc} */
  public function save(array $form, FormStateInterface $form_state) {
    $node = $this->entity;
    $insert = $node->isNew();
    $node->save();
    $node_link = $node->toLink($this->t('View'))->toString();
    $context = ['@type' => $node->getType(), '%title' => $node->label(), 'link' => $node_link];
    $t_args = ['@type' => node_get_type_label($node), '%title' => $node->toLink()->toString()];

    if ($insert) {
      $this->logger('content')->info('@type: added %title.', $context);
      $this->messenger()->addStatus($this->t('@type %title has been created.', $t_args));
    }
    else {
      $this->logger('content')->info('@type: updated %title.', $context);
      $this->messenger()->addStatus($this->t('@type %title has been updated.', $t_args));
    }

    

  public function getCacheMaxAge() {
    return $this->getCacheMetadata()->getCacheMaxAge();
  }

  /** * {@inheritdoc} */
  public function listTopics() {
    // Map the top level help topic plugins to a list of topic links.     return array_map(function DHelpTopicPluginInterface $topic) {
      return $topic->toLink();
    }$this->getPlugins());
  }

  /** * Gets the top level help topic plugins. * * @return \Drupal\help_topics\HelpTopicPluginInterface[] * The top level help topic plugins. */
  protected function getPlugins() {
    if (!isset($this->topLevelPlugins)) {
      
    // by name.     $admin_user->name = 'Admin user';
    $admin_user->save();
    $this->drupalLogin($admin_user);
    $this->drupalGet('admin/people');
    $this->assertSession()->pageTextContains($user_a->getAccountName());
    $this->assertSession()->pageTextContains($user_b->getAccountName());
    $this->assertSession()->pageTextContains($user_c->getAccountName());
    $this->assertSession()->pageTextContains($admin_user->getAccountName());

    // Test for existence of edit link in table.     $link = $user_a->toLink('Edit', 'edit-form', ['query' => ['destination' => $user_a->toUrl('collection')->toString()]])->toString();
    $this->assertSession()->responseContains($link);

    // Test exposed filter elements.     foreach (['user', 'role', 'permission', 'status'] as $field) {
      $this->assertSession()->fieldExists("edit-$field");
    }
    // Make sure the reduce duplicates element from the ManyToOneHelper is not     // displayed.     $this->assertSession()->fieldNotExists('edit-reduce-duplicates');

    // Filter the users by name/email.
return $this->protectBundleIdElement($form);
  }

  /** * {@inheritdoc} */
  public function save(array $form, FormStateInterface $form_state) {
    $block_type = $this->entity;
    $status = $block_type->save();

    $edit_link = $this->entity->toLink($this->t('Edit'), 'edit-form')->toString();
    $logger = $this->logger('block_content');
    if ($status == SAVED_UPDATED) {
      $this->messenger()->addStatus($this->t('Block type %label has been updated.', ['%label' => $block_type->label()]));
      $logger->notice('Block type %label has been updated.', ['%label' => $block_type->label(), 'link' => $edit_link]);
    }
    else {
      block_content_add_body_field($block_type->id());
      $this->messenger()->addStatus($this->t('Block type %label has been added.', ['%label' => $block_type->label()]));
      $logger->notice('Block type %label has been added.', ['%label' => $block_type->label(), 'link' => $edit_link]);
    }

    

  public function buildHeader() {
    $header['type'] = $this->t('Block type');
    $header['description'] = $this->t('Description');
    return $header + parent::buildHeader();
  }

  /** * {@inheritdoc} */
  public function buildRow(EntityInterface $entity) {
    $row['type'] = $entity->toLink(NULL, 'edit-form')->toString();
    $row['description']['data']['#markup'] = $entity->getDescription();
    return $row + parent::buildRow($entity);
  }

  /** * {@inheritdoc} */
  protected function getTitle() {
    return $this->t('Block types');
  }

}
/** * {@inheritdoc} */
  public function save(array $form, FormStateInterface $form_state) {
    $vocabulary = $this->entity;

    // Prevent leading and trailing spaces in vocabulary names.     $vocabulary->set('name', trim($vocabulary->label()));

    $status = $vocabulary->save();
    $edit_link = $this->entity->toLink($this->t('Edit'), 'edit-form')->toString();
    switch ($status) {
      case SAVED_NEW:
        $this->messenger()->addStatus($this->t('Created new vocabulary %name.', ['%name' => $vocabulary->label()]));
        $this->logger('taxonomy')->notice('Created new vocabulary %name.', ['%name' => $vocabulary->label(), 'link' => $edit_link]);
        $form_state->setRedirectUrl($vocabulary->toUrl('overview-form'));
        break;

      case SAVED_UPDATED:
        $this->messenger()->addStatus($this->t('Updated vocabulary %name.', ['%name' => $vocabulary->label()]));
        $this->logger('taxonomy')->notice('Updated vocabulary %name.', ['%name' => $vocabulary->label(), 'link' => $edit_link]);
        $form_state->setRedirectUrl($vocabulary->toUrl('collection'));
        
/** @var \Drupal\node\NodeInterface[] $parent_books */
    $parent_books = $this->nodeStorage->loadMultiple($book_nids);
    $parent_books = array_map([$this->entityRepository, 'getTranslationFromContext']$parent_books);
    if (count($parent_books) > 0) {
      $depth = 1;
      while (!empty($book['p' . ($depth + 1)])) {
        if (!empty($parent_books[$book['p' . $depth]]) && ($parent_book = $parent_books[$book['p' . $depth]])) {
          $access = $parent_book->access('view', $this->account, TRUE);
          $breadcrumb->addCacheableDependency($access);
          if ($access->isAllowed()) {
            $breadcrumb->addCacheableDependency($parent_book);
            $links[] = $parent_book->toLink();
          }
        }
        $depth++;
      }
    }
    $breadcrumb->setLinks($links);
    $breadcrumb->addCacheContexts(['route.book_navigation']);
    return $breadcrumb;
  }

}
        $date = $this->dateFormatter->format($revision->revision_timestamp->value, 'short');

        // We treat also the latest translation-affecting revision as current         // revision, if it was the default revision, as its values for the         // current language will be the same of the current default revision in         // this case.         $is_current_revision = $vid == $default_revision || (!$current_revision_displayed && $revision->wasDefaultRevision());
        if (!$is_current_revision) {
          $link = Link::fromTextAndUrl($datenew Url('entity.node.revision', ['node' => $node->id(), 'node_revision' => $vid]))->toString();
        }
        else {
          $link = $node->toLink($date)->toString();
          $current_revision_displayed = TRUE;
        }

        $row = [];
        $column = [
          'data' => [
            '#type' => 'inline_template',
            '#template' => '{% trans %}{{ date }} by {{ username }}{% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}',
            '#context' => [
              'date' => $link,
              'username' => $this->renderer->renderPlain($username),
              
$this->assertEquals('entity_link', $field['plugin_id']);

    $view->initDisplay();
    $view->setDisplay('page_1');
    $view->initStyle();
    $view->rowPlugin->options['view_mode'] = 'full';

    // Test with view_mode full.     $output = $view->preview();
    $output = $renderer->renderRoot($output);
    foreach ($this->nodes as $node) {
      $this->assertStringContainsString('This is <strong>not escaped</strong> and this is ' . $node->toLink('the link')->toString()$output, 'Make sure path field rewriting is not escaped.');
    }
  }

}
// Check for a link assigned to this menu.     return $this->menuLinkManager->menuNameInUse($value);
  }

  /** * {@inheritdoc} */
  public function save(array $form, FormStateInterface $form_state) {
    $menu = $this->entity;
    $status = $menu->save();
    $edit_link = $this->entity->toLink($this->t('Edit'), 'edit-form')->toString();
    if ($status == SAVED_UPDATED) {
      $this->messenger()->addStatus($this->t('Menu %label has been updated.', ['%label' => $menu->label()]));
      $this->logger('menu')->notice('Menu %label has been updated.', ['%label' => $menu->label(), 'link' => $edit_link]);
    }
    else {
      $this->messenger()->addStatus($this->t('Menu %label has been added.', ['%label' => $menu->label()]));
      $this->logger('menu')->notice('Menu %label has been added.', ['%label' => $menu->label(), 'link' => $edit_link]);
    }

    $form_state->setRedirectUrl($this->entity->toUrl('edit-form'));
  }

  
Home | Imprint | This part of the site doesn't use cookies.