Forked from DanLaufer/list_text_long_fields.php
Last active
January 12, 2021 00:40
-
-
Save gargsuchi/6fc1b8ca5c471b5f71732e561c70f43c to your computer and use it in GitHub Desktop.
Drupal 8 - PHP Script to list all fields on all content types of a certain type (ex. text_long)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Drupal\paragraphs\Entity\Paragraph; | |
$field_type = 'text_long'; | |
// get node types | |
$node_types = \Drupal::entityTypeManager() | |
->getStorage('node_type') | |
->loadMultiple(); | |
$entityManager = \Drupal::service('entity_field.manager'); | |
// for each content type, get the text_long fields for that content type | |
foreach(array_keys($node_types) as $key => $value) { | |
$fields = $entityManager->getFieldDefinitions("node", $value); | |
$text_long_fields = array_filter( | |
$fields, | |
function ($field_value, $field_key) { | |
// only keep fields of type 'text_long' | |
return (strpos($field_value->getType(), $field_type) > -1); | |
}, ARRAY_FILTER_USE_BOTH | |
); | |
print_r(array_keys($text_long_fields)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment