Problem/Motivation

For my use case. Only the _blank target is needed/wanted inside the target selection dropdown. I'd prefer to use this module, instead of creating a custom one.

Proposed resolution

Make the list of target items configurable.

Remaining tasks

  • Create configuration form where possible target selection items can be selected with checkboxes.
  • Get configured available targets in field formatter, instead of using hardcoded ones.
  • Review & Test.
  • Commit.

User interface changes

Configuration form added.

API changes

None.

Data model changes

Available targets configuration added.

Comments

orlando.thoeny created an issue. See original summary.

orlando.thoeny’s picture

Issue summary: View changes
orlando.thoeny’s picture

I could implement this if the feature is desired.

jacobfrancke@gmail.com’s picture

Hi Orlando,

This sounds good, I don have time myself to implement this, so feel free to do this :-)

Thanks!

orlando.thoeny’s picture

Status: Active » Needs review
StatusFileSize
new17.13 KB

I created a config for the link targets. Also a settings page. Updated Readme and made it Markdown. The configuration is set via update hook for existing installs. I'd put that into the release notes. If someone runs drush cim afterwards, it will be removed, so it has to be exported to the config files first with drush cex.

orlando.thoeny’s picture

Issue summary: View changes
scuba_fly’s picture

Status: Needs review » Reviewed & tested by the community

Wow really nice! work like a charm!

Tested by updating the module with this patch. I see that you have an update hook in place that creates the config.
Totally makes sense.

It's a really big patch, but I could not find any issues with it.

I tried selecting only _blank and _self. and it just works!

mandclu’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new4.98 KB

A much simpler approach would be to make this part of the widget settings, and this would also give a site builder the option of having different targets available per content type or bundle.

The attached patch implements this approach, please test.

maursilveira’s picture

Status: Needs review » Needs work

Hello @mandclu,

I tested your patch against the dev version, and I get the following error in the form display:

The website encountered an unexpected error. Please try again later.
Error: Using $this when not in object context in Drupal\link_target\Plugin\Field\FieldWidget\LinkTargetFieldWidget::getTargets() (line 77 of modules/contrib/link_target/src/Plugin/Field/FieldWidget/LinkTargetFieldWidget.php).

Drupal\link_target\Plugin\Field\FieldWidget\LinkTargetFieldWidget::getTargets() (Line: 42)
Drupal\link_target\Plugin\Field\FieldWidget\LinkTargetFieldWidget->settingsForm() (Line: 455)
Drupal\field_ui\Form\EntityDisplayFormBase->buildFieldRow() (Line: 40)
Drupal\field_ui\Form\EntityFormDisplayEditForm->buildFieldRow() (Line: 218)
Drupal\field_ui\Form\EntityDisplayFormBase->form() (Line: 149)
Drupal\Core\Entity\EntityForm->buildForm()
call_user_func_array() (Line: 532)
Drupal\Core\Form\FormBuilder->retrieveForm() (Line: 278)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 91)
Drupal\Core\Controller\FormController->getContentResult()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 57)
Drupal\Core\StackMiddleware\Session->handle() (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 91)
Drupal\shield\ShieldMiddleware->handle() (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 23)
Stack\StackedHttpKernel->handle() (Line: 708)
Drupal\Core\DrupalKernel->handle() (Line: 19)

The problem is that you are using $this inside a static function.

You can either make that function not static or simply use t().

Thank you.

mandclu’s picture

StatusFileSize
new4.96 KB

@maursilveira thanks for the feedback. Here's an updated patch that should address the error you found.

mandclu’s picture

Status: Needs work » Needs review
maursilveira’s picture

Hello @mandclu.

Patch #10 fixes the reported issue, and it works great. I took the liberty to add a couple of changes to it in the patch attached into this comment.

1. Display the message "No target options were selected." in the function settingsSummary() if no available target options are selected. The previous code was displaying "Available targets:".
2. Remove the select element "Select a target" from the add/edit form if no available target options are selected. The previous code generated the target selector, but the only option was "- None -".

Could you please review it? Please let me know what you think about this, or if you have any questions.

Thank you.

Mauricio

mandclu’s picture

Thanks for the additional feedback. I agree that the previous patch didn't properly handle an empty set of targets, but I think the solution should be to default to showing all instead. If they don't want any targets allowed, why use this widget at all?

Here's an updated patch that should fix the behaviour, to show all target options if none were selected.

I wasn't able to generate an interdiff from your patch (the error was "Whitespace damage detected in input") so providing an interdiff from the patch in #10 instead.

maursilveira’s picture

Status: Needs review » Reviewed & tested by the community

Hello @mandclu,

I totally agree with you. I made that change to hide the filter when no available options were selected because I thought that was by design. But I agree that if no options are manually selected that should mean that all options will be available.

I tested the patch in #13 and it works great. Thank you for the patch.

Mauricio

  • mandclu authored ad911bb on 8.x-1.x
    Issue #3044960 by mandclu, orlando.thoeny, maursilveira, scuba_fly: Make...
mandclu’s picture

Thanks again for all your feedback and help on this issue. Merged in, and will roll a new release shortly.

mandclu’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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