Hot answers tagged


You can do this by implementing hook_entity_view_display_alter in a custom module. Some code like this should work: function HOOK_entity_view_display_alter(\Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, array $context) { if ( $context['entity_type'] == 'node' && $context['bundle'] == 'CUSTOM_CONTENT_TYPE' && (...


The code from your question should work in a hook_install(). But you need a lot more configuration for a content type, which you can create the easiest way in UI. See the comment of @Hudri. Then export the configuration to the config folder of your module, see Organizing config for use with a module


Your problem is here: use Drupal\node\Entity\Node; use Drupal\taxonomy\Entity\Term; use Drupal\views\ViewExecutable; use Drupal\views\Views; use Drupal\Core\Render; $nid = 1; $entity_type = 'node'; $view_mode = 'teaser'; $builder = \Drupal::service('entity_type.manager')->getViewBuilder($entity_type); $storage = \Drupal::service('entity.manager')->...

Only top voted, non community-wiki answers of a minimum length are eligible