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.
Comments
Comment #2
trackleft2Comment #3
trackleft2Comment #4
vlad.dancerHi @trackleft2. Thank you for the improvement. Sure, I would glad to review and merge MR!
Comment #6
trackleft2This 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.
Comment #7
trackleft2Comment #8
trackleft2Adding a patch against 4.0.x
Comment #9
vlad.dancerComment #11
vlad.dancerThank you @trackleft2. Commited!