Modify parent entity from within custom field formatter How can I modify parent entity's output from within my custom field. I am writing a custom field that adds css class to blocks. Everything is set, except I don't know how to modify the parent entity.
You can do this from inside the field formatter.  Each of the $items passed into the viewElements method has a getEntity() method that will give you the entity.

class MyFieldFormatter extends FormatterBase {

  public function viewElements(FieldItemListInterface $items, $langcode) {
    $entity = $items[0]-&gt;getEntity();
  }

}


However, this is not recommended since it inverts the normal control flow. In normal situations, everything needed to render a field is a value on a column in the field itself.  Grabbing the entity is icky, but is definitely possible for strange edge cases.