Get the values of a checkbox field in node when evaluating in block condition plugin I have a field that is a checkbox with multiple values... I'm trying to do an evaluation in a condition plugin where I'm checking against the checked values. For a boolean field, the syntax is:

$value = $this->getContextValue('node')->field_news_filter_menus->value;

Since field_news_filter_menus is a checkboxes field, I need to get the array of checked values.
These all return null:
$this->getContextValue('node')->field_news_filter_menus->list->values;
$this->getContextValue('node')->field_news_filter_menus->values;
$this->getContextValue('node')->field_news_filter_menus->list;

PHPstorm xdebug says the path is $this->getContextValue('node')->field_news_filter_menus->list[0]->value;
But null is returned for that also.
I can see the values in xdebug that follow a path as $this->getContextValue('node')->field_news_filter_menus->list[0]->values and see an expected value, but that path also returns null.

What is the syntax for getting that array list?
Original Answer

The proper way to access field values is $entity-&gt;get('my_field')-&gt;getValue() in your case this will return an array like:

Array(
  0 =&gt; Array(
    'value' =&gt; 'value1'
  ),
  1 =&gt; Array(
    'value' =&gt; 'value2'
  ),
  2 =&gt; Array(
    'value' =&gt; 'value3'
  ),
  // And so on as many values your field has.
)


Also you can check if the field is empty by calling $entity-&gt;get('my_field')-&gt;isEmpty(). Calling only your field like $entity-&gt;get('my_field') will NOT return the field value but the field instance. Calling for an unexisting field will throw a runtime exception.

UPDATE

To check if the value exists you can either iterate over the array or do something like this

$arr = [
  0 =&gt; [
    'value' =&gt; 'value1',
  ],
  1 =&gt; [
    'value' =&gt; 'value2',
  ],
  2 =&gt; [
    'value' =&gt; 'value3',
  ],
];

$arr = array_map(function ($v) {
  return $v['value'];
}, $arr);

assert(in_array('value2', $arr, TRUE), 'Assert that contains value2');
assert(in_array('other', $arr, TRUE), 'Assert that contains other. This will fail');


You can try it here.