Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OEL-1571: Display country instead skos entity reference country URL. #150

Merged
merged 3 commits into from
Jun 2, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,11 @@ function oe_whitelabel_contact_forms_preprocess_status_messages(&$variables) {
if ($field->isEmpty() || !$field->access()) {
continue;
}
$value = 'value';
if ($field->getFieldDefinition()->getType() == 'skos_concept_entity_reference') {
$value = 'target_id';
}
$items[] = [
'term' => $field->getFieldDefinition()->getLabel(),
'definition' => $field->first()->getValue()[$value],
'definition' => $field->getFieldDefinition()->getType() === 'skos_concept_entity_reference'
? $field->referencedEntities()
: $field->first()->getValue()['value'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong indentation. I know it is PhpStorm's fault but we should fix manually.

Suggested change
'definition' => $field->getFieldDefinition()->getType() === 'skos_concept_entity_reference'
? $field->referencedEntities()
: $field->first()->getValue()['value'],
'definition' => $field->getFieldDefinition()->getType() === 'skos_concept_entity_reference'
? $field->referencedEntities()
: $field->first()->getValue()['value'],

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, by passing a Concept entity to the template, the template will implicitly call ->label() on that entity, through this line in bcl-descritpion-list.html.twig:

                {{- _definition.label -}}

This is how it works: If the value is an object, then it will try $obj->$key and then $obj->$key().
See twig_get_attribute(). Crazy, eh?

Let's not rely on this magic.
Instead, let's do something like this:
(please don't copy this 1:1, it is only for the rough direction)

/** @var \Drupal\rdf_skos\Entity\Concept[] $concept_entities */
$concept_entities = $field->referencedEntities();
if (!isset($concept_entities[0])) {
  continue;
}
$items[] = [
  'term' => $field->getFieldDefinition()->getLabel(),
  'definition' => [['label' => $concept_entities[0]->label()]],
];

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is complex enough that we should use if/else instead of a ternary.

];
}
$variables['message_list']['status'][$key] = [
Expand Down