I am trying to get values from a multi-select field. I think I'm getting the keys and not the values. The output is 'cell_phone' instead of 'cell phone', for example.
I also am seeing a warning about 'undefined array key', category, which I thought I initialized. Here is my code. What is wrong with the code?
Thank you.
$categorylist[] = “”;
foreach ($node->get('field_category') as $category_value) {
if ( !empty($category_value ) ){
$variables['categorylist'] .= $category_value->value . ", ";
}
}
in Twig file:
{% if categorylist %}
{{categorylist}}
{% endif %}