22
33namespace Drupal \view_mode_selector \Plugin \Field \FieldWidget ;
44
5- use Drupal \Core \Entity \EntityManagerInterface ;
5+ use Drupal \Core \Entity \EntityDisplayRepositoryInterface ;
66use Drupal \Core \Field \WidgetBase ;
77use Drupal \Core \Field \FieldDefinitionInterface ;
88use Drupal \Core \Plugin \ContainerFactoryPluginInterface ;
@@ -21,9 +21,9 @@ abstract class ViewModeSelectorWidgetBase extends WidgetBase implements Containe
2121 protected $ viewModes = [];
2222
2323 /**
24- * @var \Drupal\Core\Entity\EntityManagerInterface
24+ * @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface
2525 */
26- protected $ entityManager ;
26+ protected $ entityDisplayRepository ;
2727
2828 /**
2929 * ViewModeSelectorWidgetBase constructor.
@@ -33,18 +33,18 @@ abstract class ViewModeSelectorWidgetBase extends WidgetBase implements Containe
3333 * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
3434 * @param array $settings
3535 * @param array $third_party_settings
36- * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
36+ * @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository
3737 */
38- public function __construct ($ plugin_id , $ plugin_definition , FieldDefinitionInterface $ field_definition , array $ settings , array $ third_party_settings , EntityManagerInterface $ entity_manager ) {
38+ public function __construct ($ plugin_id , $ plugin_definition , FieldDefinitionInterface $ field_definition , array $ settings , array $ third_party_settings , EntityDisplayRepositoryInterface $ entity_display_repository ) {
3939 parent ::__construct ($ plugin_id , $ plugin_definition , $ field_definition , $ settings , $ third_party_settings );
40- $ this ->entityManager = $ entity_manager ;
40+ $ this ->entityDisplayRepository = $ entity_display_repository ;
4141
4242 $ field_settings = $ field_definition ->getSettings ();
4343 $ entity_type = $ field_definition ->getTargetEntityTypeId ();
4444 $ bundle = $ field_definition ->getTargetBundle ();
4545
4646 // Get all view modes for the current bundle.
47- $ view_modes = $ this ->entityManager ->getViewModeOptionsByBundle ($ entity_type , $ bundle );
47+ $ view_modes = $ this ->entityDisplayRepository ->getViewModeOptionsByBundle ($ entity_type , $ bundle );
4848
4949 // Reduce options by enabled view modes
5050 foreach (array_keys ($ view_modes ) as $ view_mode ) {
@@ -56,7 +56,7 @@ public function __construct($plugin_id, $plugin_definition, FieldDefinitionInter
5656
5757 // Show all view modes in widget when no view modes are enabled.
5858 if (!count ($ view_modes )) {
59- $ view_modes = $ this ->entityManager ->getViewModeOptionsByBundle ($ entity_type , $ bundle );
59+ $ view_modes = $ this ->entityDisplayRepository ->getViewModeOptionsByBundle ($ entity_type , $ bundle );
6060 }
6161
6262 $ this ->viewModes = $ view_modes ;
@@ -66,6 +66,6 @@ public function __construct($plugin_id, $plugin_definition, FieldDefinitionInter
6666 * {@inheritdoc}
6767 */
6868 public static function create (ContainerInterface $ container , array $ configuration , $ plugin_id , $ plugin_definition ) {
69- return new static ($ plugin_id , $ plugin_definition , $ configuration ['field_definition ' ], $ configuration ['settings ' ], $ configuration ['third_party_settings ' ], $ container ->get ('entity.manager ' ));
69+ return new static ($ plugin_id , $ plugin_definition , $ configuration ['field_definition ' ], $ configuration ['settings ' ], $ configuration ['third_party_settings ' ], $ container ->get ('entity_display.repository ' ));
7070 }
7171}
0 commit comments