I am trying to port my Drupal 7 module, Views Hybrid, to Drupal 8. It provides a custom field formatter. In order to provide the field formatter, I am using the Doctrine annotation roughly following this tutorial provided by realize.be. However, I am getting PHP exceptions:
Uncaught PHP Exception Doctrine\Common\Annotations\AnnotationException:
"[Syntax Error] Expected PlainValue, got '>'
at position 168 in class
Drupal\views_hybrid\Plugin\Field\FieldFormatter\HybridFormatter."
at ~/core/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php line 41
If I remove the double quotes from the keys inside the settings
array then I get a different error:
Uncaught PHP Exception Doctrine\Common\Annotations\AnnotationException:
"[Semantical Error] Couldn't find constant items_count, class Drupal\views_hybrid\Plugin\Field\FieldFormatter\HybridFormatter."
at ~/core/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php line 52
/**
* Plugin implementation of the 'views_hybrid' formatter.
*
* @FieldFormatter(
* id = "views_hybrid",
* label = @Translation("Views hybrid"),
* field_types = {"entity_reference"},
* settings = {
* "items_count" => "5",
* "view" => "frontpage",
* "display" => "linked_title_only",
* "classes" => {},
* "view_mode" => "teaser",
* "arguments" => "",
* },
* )
*/
I am not clear about the syntax that Doctrine expects for these nested arrays, or even on whether Drupal 8 expects the settings array to be included in the Doctrine annotations block when declaring a new field formatter, and my usually debugging techniques aren't very useful for debugging annotations since they're not exactly code. What is the expected syntax and content of a Doctrine annotation for defining a field formatter in Drupal 8?