Originally issue was added to Drupal core project. See the comments from core maintainers to know why it should not be in core but in Search API project.

Problem/Motivation

In some cases there is need to populate configuration with a list of bundles that are available in Drupal. For example, you create a search api index and add the field "Rendered HTML output":

Rendered HTML output field in Search API index

This field has configuration to select what view display to use for each bundle of datasource entity that is used for index:

Configuration of Rendered HTML output field

When using recipe, it is not possible to know in advance what content types (entity bundles) are there in Drupal. So, it would be nice to have an option to set this setting for all entity bundles at the same time. Maybe create a wildcard option? Or `all` option and then it could be overwritten by each bundle setting?

Another example is a view based on Search API Index. If you use the "Rendered Entity" as a style for "Format":

View with rendered entity format

Then in the settings there will be this selection of view display for each entity bundle:

Views Rendered Entity format settings

They are similar to previous example. It would be nice to set an option that will work for all bundles. Not only because there is no way to know all the bundles in advance but also when adding a new content type, by default it won't be even included in search index for "Render HTML output" field. For the users who are not familiar with how to configure search api this is a blocker. If recipe provides setting for all existing and future bundles this would be a solution, so that users do not need to worry about. If an experienced user wants to be more granular and set different view modes, it is still possible and this type of users will know where and how to do that.

Steps to reproduce

Create couple of content types.
Create a view with Format "Rendered Entity".
Observe in settings the dropdown with view display for each bundle.

Proposed resolution

Create ability to set an option for all bundles and overwrite per bundle with existing functionality. This is needed at least for search_api row style plugin in views and rendered_item processor

Issue fork search_api-3483366

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

a.dmitriiev created an issue. See original summary.

thejimbirch’s picture

Issue tags: +Recipes initiative
phenaproxima’s picture

I am a fairly strong -1 on this.

It's just...too fiddly. It's trying to make a generic action to do something that is inherently not generic. Generic actions should only be added to do things that work the same way on every config entity type (or nearly every type). To me, this is 1000% a case to create a custom action in Search API.

If we were going to pursue something like this, we'd have to have think through it very carefully (all the use cases and implications thereof). An action like what you're proposing, to me, feels like treating all config as though it's composed of dumb arrays. Which is true on one level (and it's certainly true of simple config)...but very dangerous to generalize. Config entities have setter methods and APIs for a reason.

So my preference is to close this issue as a wontfix, and pursue more specific actions in Search API and Views to configure indexes and views the way we want.

a.dmitriiev’s picture

Status: Active » Closed (won't fix)

Ok, thank you for the feedback. Let's continue in corresponding projects.

BTW, simpleConfigUpdate in the example was just for example. The idea was to use the %bundle placeholder in another config actions, not required that it is simpleConfigUpdate

a.dmitriiev’s picture

Title: Need a way to populate some config values with list of available entity bundles with config actions » Allow to set the same view mode for all entity bundles in Search API plugins
Project: Drupal core » Search API
Version: 10.4.x-dev » 8.x-1.x-dev
Component: recipe system » Plugins
Status: Closed (won't fix) » Active
a.dmitriiev’s picture

Issue summary: View changes
drunken monkey’s picture

Thanks for creating this issue!
It’s indeed not ideal UX that you have to configure the view mode for each bundle separately, especially if you add bundles after configuring the row style or field. (The field will at least post warnings to the log to point the user to this problem.)

For field-based processor (like Tokenizer, Ignore Case, etc.) we already have something similar, the “Enable on all supported fields” option added in #2867809: Add new fulltext fields to enabled fields processors. That solved a very similar problem, namely the need to reconfigure all these processors when adding a new fulltext field. The solution here would be a bit more complicated, as it’s a select instead of a checkbox and we still need separate settings for different datasources (entity types), but seems something similar could work here, too.

Maybe like this: For each datasource, we have a select box with all the different view modes for that datasource, plus an option that says something like “Select per bundle”. When that latter option is selected, we display the additional select boxes for each bundle, otherwise the datasource setting juts applies to all bundles and the bundle-specific settings get hidden.
Alternatively, the datasource-level setting could just have the view modes as options, the bundle-specific select boxes could always be visible but we add a new default option to them, “Use datasource-level default”. (All labels mentioned here up for debate.)

If you want to work on an MR implementing something like this, that would be great!

a.dmitriiev’s picture

I have started a draft MR. At the moment I made the changes only to the "Rendered Item" plugin for index field. Not fully tested yet. I will continue tomorrow, as this feature is really needed for Drupal CMS.

a.dmitriiev’s picture

StatusFileSize
new8.33 KB

Uploading the patch to use in Drupal CMS

a.dmitriiev’s picture

StatusFileSize
new8.33 KB

Updated patch without strange symbols

a.dmitriiev’s picture

StatusFileSize
new8.11 KB

Patch for version 1.35

a.dmitriiev’s picture

Status: Active » Needs review

Please disregard patches and review MR. The patches are just needed to be used with stable 1.35 version.

a.dmitriiev’s picture

Issue tags: +Starshot blocker
borisson_’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

So this change does not need a new config action, it only needs this change and the config action/recipe will set it to the new :all selection?

I think this is a good solution and I can't find anything to complain about really, apart from there not being any test coverage.

At the least I think we should add to the RenderedItemTest.

drunken monkey’s picture

Thanks for your work on this!
I went over the code and found a few places where a) the wording of UI text could be improved or b) the code wasn’t working 100% correctly in all cases anymore. All of this should now be fixed in the MR. Please test/review my changes and tell me what you think.

In any case, I agree with @borisson_, this definitely needs some test coverage. The number of potential code paths in \Drupal\search_api\Plugin\search_api\processor\RenderedItem::addFieldValues() borders on disconcerting.
I did, however, now already adapt all the views included in the module (mainly test views) that use the SearchApiRow plugin to utilize the new :default option, so we should at least get some very rough test coverage for the Views part that way. As our test coverage for the Views integration is generally rather shoddy, I’m not sure whether doing more is necessary, though it would of course be great.

a.dmitriiev’s picture

Thank you all for the feedback and review. I will try to add tests and go over all suggestions asap.

@drunken monkey, now MR looks much nicer!

a.dmitriiev’s picture

Status: Needs work » Needs review

I have added the test for global default view mode set. The test also includes the override for one bundle. Please review.

a.dmitriiev’s picture

StatusFileSize
new8.58 KB

Updated patch for 1.35 to use in Drupal CMS search track recipe

a.dmitriiev’s picture

StatusFileSize
new8.55 KB

Fixed patch for 1.35

borisson_’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

I think this is all the test coverage we need. Looks good to me.

drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

Great job, thanks! Merged.
Thanks again!

  • drunken monkey committed 1bce2a80 on 8.x-1.x
    Follow-up to #3483366 by drunken monkey: Fixed unchecked array access in...

Status: Fixed » Closed (fixed)

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