drupal-paragraphs
Skill71 starsChanged 7 months agoMITView on GitHub
Drupal Paragraphs module — accessing paragraph entities, rendering, altering paragraph forms, and patterns for custom paragraph behavior.
In this repository35 other files it gives its agents.
- ddev-expertSkill
- docker-localSkill
- drupal-accessSkill
- drupal-cachingSkill
- drupal-composerSkill
- drupal-configSkill
- drupal-contrib-mgmtSkill
- drupal-debuggingSkill
- drupal-drushSkill
- drupal-dttSkill
- drupal-entity-apiSkill
- drupal-eventsSkill
- drupal-fieldsSkill
- drupal-form-ajaxSkill
- drupal-form-alterSkill
- drupal-form-apiSkill
- drupal-form-validationSkill
- drupal-hooksSkill
- drupal-htmxSkill
- drupal-javascriptSkill
- drupal-kernelSkill
- drupal-menusSkill
- drupal-migrationsSkill
- drupal-pluginsSkill
- drupal-queriesSkill
- drupal-renderSkill
- drupal-routesSkill
- drupal-search-apiSkill
- drupal-securitySkill
- drupal-servicesSkill
- drupal-stateSkill
- drupal-taxonomySkill
- drupal-twigSkill
- drupal-unitSkill
- SKILL.mdSkill
The file
Files
Drupal Paragraphs
Accessing Paragraphs from a Node
use Drupal\paragraphs\Entity\Paragraph;
// Get all paragraphs from a field
$items = $node->get('field_content')->referencedEntities();
foreach ($items as $paragraph) {
/** @var \Drupal\paragraphs\Entity\Paragraph $paragraph */
$bundle = $paragraph->bundle();
$value = $paragraph->get('field_text')->value;
}
// Get first paragraph
$paragraph = $node->get('field_content')->first()?->entity;Creating Paragraphs Programmatically
$paragraph = Paragraph::create([
'type' => 'text_block',
'field_title' => 'My Title',
'field_body' => [
'value' => 'Body content',
'format' => 'basic_html',
],
]);
$paragraph->save();
$node->get('field_content')->appendItem([
'target_id' => $paragraph->id(),
'target_revision_id' => $paragraph->getRevisionId(),
]);
$node->save();Altering Paragraph Forms
#[Hook('field_widget_single_element_paragraphs_form_alter')]
public function fieldWidgetParagraphsFormAlter(array &$element, FormStateInterface $form_state, array $context): void {
$paragraph = $element['#paragraph'];
if ($paragraph->bundle() === 'text_block') {
// Alter the text_block paragraph form element.
$element['subform']['field_title']['#access'] = FALSE;
}
}Rendering Paragraphs
// Build render array for a paragraph
$view_builder = $this->entityTypeManager->getViewBuilder('paragraph');
$build = $view_builder->view($paragraph, 'default');Paragraph in Twig
{# Render paragraph field #}
{{ content.field_content }}
{# Iterate paragraphs #}
{% for item in content.field_content['#items'] %}
{{ item.entity.field_text.value }}
{% endfor %}Common Bundle Check Pattern
foreach ($node->get('field_content')->referencedEntities() as $paragraph) {
/** @var \Drupal\paragraphs\Entity\Paragraph $paragraph */
switch ($paragraph->bundle()) {
case 'text_block':
// Handle text block.
break;
case 'image_block':
// Handle image block.
break;
}
}Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

