1

I've developed a Views field plugin that extracts the value from another field in the view in order to apply some math. The plugin works great at getting the original value of the field. However, I would like users to be able to get the rewritten value of a given field. I've been searching around, but can't seem to find any documentation on this.

With the following code I can get the value of another field:

public function getValue(ResultRow $values, $field = NULL) {
  parent::getValue($values, $field);

  $field = $this->options['data_field'];
  $value = $values->_entity->get($field)->value;

  // I have some logic here that's not necessary for this question.

  return $value;
}

What would I need to do within the above function to get the value of $field if $field had been rewritten via someone checking the "Override the output of this field with custom text" checkbox?

0

This is how I went about getting the "alter" value for my project:

if ($this->displayHandler->getHandler('field', $field)->options['alter']['alter_text'] == 1) {
  $value = $this->displayHandler->getHandler('field', $field)->options['alter']['text'];
}
else {
  $value = $values->_entity->get($field)->value;
}
| improve this answer | |
0

Use advancedRender(), which renders an entity field respecting advanced settings including field rewrites:

$value = $this->view->field[$field_name]->advancedRender($values);
| improve this answer | |

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.