- Issue created by @pdureau
- First commit to issue fork.
- Merge request !95643475492:Link field type: Add is_external computed property → (Open) created by Walli
- 🇮🇳India KumudB Ahmedabad
After checking out the branch where @walli made changes, I applied a custom hook in the module file. As a result, the is_external field now appears as a filter option. I have attached a screenshot for reference and custom module code.
Steps to Reproduce:
Step 1: Set Up a Content Type with a Link Field
1.Create a Custom Content Type:- Go to Structure -> Content types.
- Click on Add content type and create a new content type (e.g., "Article with Link").
- Add necessary fields like "Title" and "Body."
2. Add a Link Field:
- While editing the content type, click on the Manage fields tab.
- Add a new field, select Link as the field type, and name it something like "External Link."
3.Create Content:
- Create a few nodes for this content type.
- Populate the link field with both external links (e.g., https://example.com) and internal links (e.g., /node/1).
Step 2: Check for Limitations in Default Views
1.Create a View:- Go to Structure -> Views.
- Click on Add view.
- Create a new view based on the "Article with Link" content type.
- In the view, try to add filters or sorts based on whether the link is external or internal.
2.Observation:
- Notice that there is no built-in way to filter or sort content based on whether the link is external or internal.
The MR code remian as it is and just apply this hook
/** * Implements hook_views_data_alter(). */ function customTest_views_data_alter(array &$data) { $field_name = 'field_external'; // Replace with your link field's machine name. if (isset($data["node__{$field_name}"])) { // Define the custom field handler. $data["node__{$field_name}"]['is_external'] = [ 'title' => t('Is External'), 'help' => t('Indicates if the link is external.'), 'field' => [ 'id' => 'is_external_field', // Use the ID from the @ViewsField annotation in IsExternalField. ], 'filter' => [ 'id' => 'boolean', ], 'sort' => [ 'id' => 'standard', ], 'group' => t('Custom'), ]; } }
- 🇬🇧United Kingdom andrew.farquharson
I see no test in the MR. A test is required.
- 🇫🇷France pdureau Paris
Indeed Oily. We already know about that but adding the tag is a good idea.
- 🇫🇷France pdureau Paris
Thanks you @kumudb for the proposal. We will have a look and credit you if we integrate it into the MR.