Drupal 8, programmatically enter a list of custom content fields

I want to create programmable content (user content created using the admin user interface). But before creating, I want to programmatically check the field types of my custom content

My custom content contains a body field (type text), a description field (text type), an int field (int type), a file attachment field (fid type?) ...

I am testing several ways with the new Drupal 8 api, my last attempt.

// I get the entity object "my_custom_content"
$entity_object = NodeType::load("my_custom_content");
dpm($entity_object); //Work perfectly


$test = \Drupal::getContainer()->get("entity_field.manager")->getFieldDefinitions("my_custom_content",$entity_object->bundle())
//The \Drupal::getConta... Return an error : The "my_custom_content" entity type does not exist.

With this $ entity_object, how can I get a list of fields of my custom content? I see the EntityFieldManager class, the FieldItemList class ... But I still don't understand how to play with drupal 8 / class / poo ...: /

Thanks!

+4
3

NodeType - (config) Node (content).

:

\Drupal::service('entity_field.manager')->getFieldDefinitions('node', 'my_custom_content');

entity_type, :

\Drupal::service('entity_field.manager')->getFieldDefinitions(ENTITY_TYPE_ID, BUNDLE_ID);

, id multy_purpose_link, ENTITY_TYPE_ID BUNDLE_ID multy_purpose_link

\Drupal::service('entity_field.manager')->getFieldDefinitions('paragraph', 'multy_purpose_link');
+6

$field_defs = \Drupal::service('entity_field.manager')->getFieldDefinitions('taxonomy_term', '<taxonomy machine name here>');

field_definitions

0

. getFieldDefinitions() .

$node = Node::load($slide_id);
$field_defs = $node->getFieldDefinitions();
0

Source: https://habr.com/ru/post/1617531/


All Articles