Problem/Motivation

In order to make link labels easier to override, we should use a renderable array.

In https://git.drupalcode.org/project/intelligencebank/-/blob/4.0.x/modules...

I am seeing this


  $link_url = Url::fromRoute('id_dam_media.asset_browser_form');
  $link_url->setOptions([
    'attributes' => [
      'class' => ['use-ajax', 'button', 'button--primary'],
      'data-dialog-type' => 'modal',
      'data-dialog-options' => Json::encode([
        'dialogClass' => 'media-library-widget-modal',
        'width' => '75%',
        'height' => 'window.innerHeight',
        'minHeight' => 500,
      ]),
    ],
    'query' => $formState->get('media_library_state')->all(),
  ]);

  $form['ib_dam_container'] = [
    "#type" => "container",
    'asset_browser' => [
      '#type' => 'markup',
      '#markup' => Link::fromTextAndUrl(t('Open IntelligenceBank Browser'), $link_url)->toString(),
      '#attached' => ['library' => [
        'core/drupal.dialog.ajax',
        'ib_dam/ckeditor',
      ]]
    ],
  ];

But it could be this ($link->toRenderable();instead of using the '#markup' element) , and then it is easier to override the button text

    $url = Url::fromRoute('id_dam_media.asset_browser_form');
    $url->setOptions([
      'attributes' => [
        'class' => ['use-ajax', 'button', 'button--primary'],
        'data-dialog-type' => 'modal',
        'data-dialog-options' => Json::encode([
          'dialogClass' => 'media-library-widget-modal',
          'width' => '75%',
          'height' => 'window.innerHeight',
          'minHeight' => 500,
        ]),
      ],
      'query' => $form_state->get('media_library_state')->all(),
    ]);

    $link = Link::fromTextAndUrl(t('Open IntelligenceBank Browser'), $url);
    $renderable_link = $link->toRenderable();
    $renderable_link['#attached']['library'][] = 'core/drupal.dialog.ajax';
    $form['ib_dam_container']['asset_browser'] = $renderable_link;

Please let me know if you think this is a possibility, and I can make a Merge Request.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

trackleft2 created an issue. See original summary.

trackleft2’s picture

Issue summary: View changes
trackleft2’s picture

Issue summary: View changes
vlad.dancer’s picture

Hi @trackleft2. Thank you for the improvement. Sure, I would glad to review and merge MR!

trackleft2’s picture

Status: Active » Needs review

This should be ready for review, please turn on PHPunit tests https://www.drupal.org/node/2940790/qa to ensure no regressions.

You might need to merge this Merge request before tests will pass, as the old tests only work in the 3.x branch, and not with the latest release.

trackleft2’s picture

StatusFileSize
new649.27 KB

screenshot of tests all passing.

trackleft2’s picture

Adding a patch against 4.0.x

vlad.dancer’s picture

vlad.dancer’s picture

Status: Needs review » Fixed

Thank you @trackleft2. Commited!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.