3

I am working on a project which implements a custom views filter; more specifically based on the InOperator class.

I have been following the guide below to implement the custom filter: Creating a custom Views filter in Drupal 8 and the repo used in that guide may be obtained here: Accompanying GitHub repo

Everything works with both my custom filter, and the filter provided in the referenced guide whilst inspecting in the views preview, however when the view is saved, the website crashes with the following error:

InvalidArgumentException: The configuration property display.default.display_options.filters.node_titles.value.my_title doesn't exist. in Drupal\Core\Config\Schema\ArrayElement->get() (line 74 of core/lib/Drupal/Core/Config/Schema/ArrayElement.php)

Any advice on how to fix this or if there are any steps that have been missed out would be greatly appreciated; even if a link could be provided to more recent documentation as I have not found much on this subject other than reading through the base classes. Even then I cannot find any reference to the error which is displayed.

To reproduce

  • Download the module in the linked repo and enable on a D8 site.
  • Create a view of nodes.
  • Add the 'Node titles' filter and select an option.
  • Save the view.

Many thanks in advance.

  • So your code is different from the git repo you are linking to? In that case it might be useful to share your own code. You are accessing an undefined property (either by accessing or assigning it wrong), but without code we won't be able to help you detect this. – Neograph734 Jul 17 '17 at 9:37
  • The same exception occurs with both my project code, and also the code linked in the question. I only posted that link so that anyone looking at it would be on the same page by accessing that code. – Jon Hockley Jul 17 '17 at 9:47
3

The problem here is that there is no schema definition defined for the new custom filter.

You need to create a file in config/schema/YOUR_MODULE.views.filter.yml

With the following definitions with the machine names to match your specific setup.

views.filter.YOUR_VARIABLE:
  type: views_filter
  label: 'Example'

views.filter_value.YOUR_VARIABLE:
  type: views.filter_value.in_operator
  label: 'Example'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.