Skip to content

Instantly share code, notes, and snippets.

@DanLaufer
Created May 29, 2019 15:55
Show Gist options
  • Save DanLaufer/ff4ee4a5fe147b9c592a0ced5d87f64b to your computer and use it in GitHub Desktop.
Save DanLaufer/ff4ee4a5fe147b9c592a0ced5d87f64b 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)
<?php
use Drupal\paragraphs\Entity\Paragraph;
// 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) {
print_r(PHP_EOL . PHP_EOL . $value . PHP_EOL);
$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(), 'text_long') > -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