Important Services in drupal 8

$contentTypes = \Drupal::service('entity.manager')->getStorage('node_type')->loadMultiple();

It will list all the content types of your current project.
It is very useful to call service(‘entity.manager’);

$type = $contentTypes->label();

This will get the Name of content type.

$type = $contentTypes->id();

This will get the slug of content type. Means the content type machine name

$form_modes = \Drupal::service('entity_display.repository')->getFormModes('node');

This will get the list of all content type form mode in current project

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s