LoginSignup
1
0

More than 3 years have passed since last update.

Drupalでビューモードを取得する方法

Posted at

ビューモード = コンテンツの閲覧画面で表示するフィールドの設定のことです(Viewsとは無関係)
entity_display.repositoryというサービスを利用することで取得することができます。

全てのエンティティタイプのビューモードの情報を取得する

\Drupal::service('entity_display.repository')->getAllViewModes()

特定のビューモードの情報を取得する

\Drupal::service('entity_display.repository')->getViewModes('node')

特定のバンドルの全てのビューモードのIDとラベルを取得する

$view_modes = \Drupal::service('entity_display.repository')->getViewModeOptionsByBundle('node', 'page');

特定のビューモードのオブジェクトを取得する

\Drupal::service('entity_display.repository')->getViewDisplay('node', 'article', 'teaser');
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0