1

The Paragraphs module seems great, but it does not provide any API (I looked at the source). So I think that will be enough to use Drupal API and/or Entity API.

About this module: it provides a new entity type 'Paragraph' and field with same name. User can create via UI 'Paragraph types' (bundles) with fields and view display settings like node entity.

My question: What's the right way to define bundle type for this entity type with custom fields in a custom module?

I think I must create fields first, using field_create_field() and field_create_instance() in hook_enable(). But what's next?

I must create bundle for paragraphs entity and attach created field, but I don't know how and any searches always send me to documentation about how programmatically create entity itself.

3

There is more easy way to do this: Use the module functions.

paragraphs.module contain these functions:

/**
 * Implements hook_install().
 */
function MYMODULE_install() {
  // Create new Bundle.
  $bundle = new stdClass();
  $bundle->name = 'Test Bundle'; // user friendly label
  $bundle->bundle = 'paragraphy_test'; // machine name
  $bundle->locked = 0;
  $status = paragraphs_bundle_save($bundle);
}
  • Is there a simple method for drupal 8? – kLezer Apr 5 '17 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.