How to get fields list in drupal 8


If you want to get all field list of a specific field type in Drupal 8 there is a easiest way to get them. Lets say you want to get all entity reference fields from all content types.

You just need to use this function in your class. You also need to load entity manager service into class.

<?php
$ref_fields = $this->entityManager->getStorage('field_storage_config')->loadByProperties(
      array(
        'settings' => array(
          'target_type' => 'node',
        ),
        'entity_type' => 'node',
        'type' => 'entity_reference',
        'deleted' => FALSE,
        'status' => 1,
      )
    );
Advertisements

  1. Leave a comment

Leave a Reply

Please log in using one of these methods to post your comment:

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

%d bloggers like this: