Problem/Motivation

I just updated to 2.0-beta7 in order to resolve a previously reported deprecation error and now I've found that my view reference field does not allow me to enable any extra settings save for Pagination and Argument. Consequently, the referenced view's title now displays across all of our existing references.

Currently on Drupal 10.1.4 with PHP 8.1 and find that the issue occurs across multiple sites.

Steps to reproduce

To verify that this was not an issue with Paragraphs (where our view reference field is normally situated), I created a new field in one of my existing content types and enabled all of the extra settings -- and then, after saving, only the Pagination and Argument options remained enabled (checked).

This how the field's config is set in the database (UUID and core hashes removed here for brevity):

field.field.paragraph.view_reference.field_view.yml

langcode: en
status: true
dependencies:
  config:
    - field.storage.paragraph.field_view
    - paragraphs.paragraphs_type.view_reference
  module:
    - viewsreference
id: paragraph.view_reference.field_view
field_name: field_view
entity_type: paragraph
bundle: view_reference
label: View
description: ''
required: true
translatable: false
default_value: {  }
default_value_callback: ''
settings:
  handler: 'default:view'
  handler_settings:
    target_bundles: null
    auto_create: false
  plugin_types:
    block: block
  preselect_views:
    events: events
    news: news
    resources: resources
  enabled_settings:
    offset: 0
    pager: pager
    argument: argument
    title: true
    limit: 0
field_type: viewsreference
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

C. S. Comfort created an issue. See original summary.

alison’s picture

I'm experiencing this issue, too! -- updated viewsreference 2.0.0-beta6 => 2.0.0-beta7, and the only "extra settings" I can enable are Argument and Pagination. I checked on an environment that still has beta6, and on that environment, I can enable/disable all the "extra settings" checkboxes.

  • My field is a simple viewsreference field on a node, no Paragraphs involved.
  • I don't lose the other "extra settings" in the node edit form until I save the field settings -- until I save the field settings (and lose the "extra settings"), the "Include View Title" checkbox still still shows in the node form. (That said, I haven't tried enabling that checkbox to see if it "works" or if it's just "there" -- and I'm afraid at this point I just need to roll back the update and carry on with work, I can't do that test right now -- but I figured I'd at least share what I saw!)
  • I don't see anything in watchdog/drupal logs.

FWIW, I'm still on Drupal 9.5.11 (PHP 8.1).

matoeil’s picture

same same here

it-cru’s picture

Same here. After downgrade to 2.0.0-beta6 all is working fine for me again on D10.1.

carlitus’s picture

Same, i need to enable "Limit results" but i cannot.

shani maurya’s picture

Priority: Normal » Critical

Same for me as well, I need to enable the "Include View Title" but It doesn't get enabled after checking the checkbox.

hartsak’s picture

Yeah, I have exactly the same problem as #6.

hartsak’s picture

Just adding some findings here after a quick debugging. Maybe these will help in solving the issue?
In my case, it looks like the extra setting for "title" has been saved as a boolean value where the code assumes it is a string.

For example from the config yml file of my "viewsreference" field:

enabled_settings:
    argument: argument
    title: true

In this example the argument works as expected, but the title doesn't.

Because of that, in the node edit form, the "Include view title" field doesn't appear. The setting for the title doesn't get through in line 154 of file
viewsreference/src/Plugin/Field/FieldWidget/ViewsReferenceTrait.php

foreach ($enabled_settings as $enabled_setting) {
  if (!empty($plugin_definitions[$enabled_setting])) {

In addition to that, the setting for title doesn't work when it is passed forward with the $enabled_settings in the file
viewsreference/src/Plugin/Field/FieldFormatter/ViewsReferenceFieldFormatter.php

$view->element['#viewsreference'] = [
  'data' => unserialize($item->getValue()['data'], ['allowed_classes' => FALSE]),
  'enabled_settings' => $enabled_settings,
  'parent_entity_type' => $parent_entity_type,
  'parent_entity_id' => $parent_entity_id,
  'parent_field_name' => $parent_field_name,
];

Not sure yet how this could be fixed, as simply manually fixing the config file and doing a config import doesn't seem to help. I have added a quick hotfix that helps in my case, but this only helps with the symptoms not with the cause. So if others have the same issue too, you can try the hotfix but a proper fix would be better :)

arthur_lorenz made their first commit to this issue’s fork.

arthur_lorenz’s picture

Status: Active » Needs review

The config schema for the field settings was off and expected integer values instead of strings. The config is saved using the option value instead of some integer/boolean, e.g.:

enabled_settings:
    offset: 'offset'
    limit: 'limit'
hosterholz’s picture

Status: Needs review » Reviewed & tested by the community

Merge request !38 solves the issue.

carlitus’s picture

For me still doesn't work. When enabled MR38 it works as before, when i submit the field edit form, only argument and pager can be enabled in Enable extra settings.

In the config export i see this:

  enabled_settings:
    argument: argument
    limit: 0
    pager: pager
    offset: 0

If i change to

  enabled_settings:
    argument: argument
    limit: 1
    pager: pager
    offset: 1

and import the new config nothing happens, i don't see the limit and offset options in the entity where the field is included.

arthur_lorenz’s picture

For me still doesn't work. When enabled MR38 it works as before, when i submit the field edit form, only argument and pager can be enabled in Enable extra settings.

In the config export i see this:

enabled_settings:
argument: argument
limit: 0
pager: pager
offset: 0

Hmm, looks like the schema did not get updated. Did you clear the cache?

If i change to

enabled_settings:
argument: argument
limit: 1
pager: pager
offset: 1

and import the new config nothing happens, i don't see the limit and offset options in the entity where the field is included.

Of course, the value should match the key, as for argument and pager. So you'll need to change it to

  enabled_settings:
    argument: argument
    limit: limit
    pager: pager
    offset: offset
carlitus’s picture

I seem to have broken the first two laws of the drupal programmer:

First law: Clear the cache
Second law: If that doesn't work clear the cache again.

And now it works, thank you very much

arthur_lorenz’s picture

Fantastic :)

ronraney’s picture

When I updated this module and upgraded to Drupal 10, all of my view blocks are now showing titles, whereas they previously did not. I think it might relate to this, since I cannot save the setting "Include View Title". Specifically, this is the case with blocks and view blocks. I'm not sure if it's related. I will try this hotfix, but if anyone has a suggestion, please share.

P.S. I applied this patch.

- Applying patches for drupal/viewsreference
https://www.drupal.org/files/issues/2023-11-07/viewsreference-3273497-27... (3273497: Passing null to parameter #1 ($data) of type string to unserialize() is deprecated)
https://www.drupal.org/files/issues/2023-11-23/viewsreference-hotfix-ena... (3400712: Enable extra settings only allows for saving of Pagination and Argument options)

I cleared cache. I went to an entity reference inside a paragraph and chose to Edit. I scrolled down to "Enable extra settings". I checked "Include View Title" and saved it. It didn't stick. I clicked Edit again and it shows as unchecked. In other words, the patch at the top of the page did not help me.

arthur_lorenz’s picture

P.S. I applied this patch.

You should've applied the patch from the referenced merge request :)

ronraney’s picture

This is what I applied:
"3400712: Enable extra settings only allows for saving of Pagination and Argument options" : "https://www.drupal.org/files/issues/2023-11-23/viewsreference-hotfix-ena..."

Appears to be the same thing.

arthur_lorenz’s picture

ronraney’s picture

OK I've never merged from github, but I added .patch to the end and found this.
https://git.drupalcode.org/project/viewsreference/-/merge_requests/38.patch

I applied the patch. It worked. Regarding my other problem, I think it resolved the "double title" issue. Now that the title toggle is there, it defaults to "no" and the title is not displayed. Before it was defaulting to display.

P.S. As it turns out, I can now select to display titles, but they don't display. I don't think it's a CSS thing. Something is broken with titles in Entity Referenced views on our site - Drupal 10.

hudri’s picture

Status: Reviewed & tested by the community » Closed (duplicate)
Related issues: +#3402036: Configuration schema for "Enable extra settings" (title,pagination,...) incorrect

This is a duplicate of #3402036

While both issues fix the problem, I don't think the the solution proposed here is correct. IMHO the correct approach is the one from 3402036: Fix the type definition in the parent sequence, not change the value type of every single item ifself.