Loading frontend_editing.module +9 −2 Changes for frontend_editing.module: 9 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -310,8 +310,15 @@ function frontend_editing_entity_view_alter(&$build, EntityInterface $entity, En ]; if ($entity->getEntityType()->hasKey('bundle')) { $build['frontend_editing']['common_actions']['title_edit']['title'] = [ '#markup' => '<span class="action-title">' . $entity->get($entity->getEntityType() ->getKey('bundle'))->entity->label() . '</span>', '#type' => 'html_tag', '#tag' => 'span', '#attributes' => [ 'class' => ['action-title'], ], 'label' => [ '#plain_text' => $entity->get($entity->getEntityType() ->getKey('bundle'))->entity->label(), ], ]; } // Add the edit link. Loading frontend_editing.routing.yml +3 −0 Changes for frontend_editing.routing.yml: 3 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -74,6 +74,7 @@ frontend_editing.paragraph_delete: _controller: '\Drupal\frontend_editing\Controller\FrontendEditingController::delete' requirements: _custom_access: '\Drupal\frontend_editing\Controller\FrontendEditingController::accessDelete' _csrf_token: 'TRUE' options: parameters: paragraph: Loading @@ -86,6 +87,7 @@ frontend_editing.paragraph_up: _controller: '\Drupal\frontend_editing\Controller\FrontendEditingController::up' requirements: _custom_access: '\Drupal\frontend_editing\Controller\FrontendEditingController::accessUp' _csrf_token: 'TRUE' options: parameters: paragraph: Loading @@ -98,6 +100,7 @@ frontend_editing.paragraph_down: _controller: '\Drupal\frontend_editing\Controller\FrontendEditingController::down' requirements: _custom_access: '\Drupal\frontend_editing\Controller\FrontendEditingController::accessDown' _csrf_token: 'TRUE' options: parameters: paragraph: Loading src/ParagraphsHelper.php +20 −0 Changes for src/ParagraphsHelper.php: 20 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -145,6 +145,10 @@ class ParagraphsHelper implements ParagraphsHelperInterface { if (!$parent_entity || !$parent_entity->access('update') || !$parent_entity->hasField($parent_field_name)) { return AccessResult::forbidden(); } // Check if it is allowed to update the field / add new paragraphs. if (!$parent_entity->get($parent_field_name)->access('edit')) { return AccessResult::forbidden('No edit access to the paragraph field.'); } // Check that the given paragraphs type is allowed. $parent_field_definition = $parent_entity->get($parent_field_name)->getFieldDefinition(); if ($parent_entity->isTranslatable() && !$parent_entity->isDefaultTranslation() && !$parent_field_definition->isTranslatable()) { Loading Loading @@ -217,6 +221,10 @@ class ParagraphsHelper implements ParagraphsHelperInterface { if (!$parent->hasField($parent_field_name) || $parent->get($parent_field_name)->isEmpty()) { return AccessResult::forbidden(); } // Check if it is allowed to update the field. if (!$parent->get($parent_field_name)->access('edit')) { return AccessResult::forbidden('No edit access to the paragraph field.'); } // By default, paragraph reference fields do not support translations. For // this reason we need to check in case the parent entity is translatable // that current translation is the default one and that the paragraph field Loading Loading @@ -275,6 +283,10 @@ class ParagraphsHelper implements ParagraphsHelperInterface { if (!$parent->hasField($parent_field_name) || $parent->get($parent_field_name)->isEmpty()) { return AccessResult::forbidden(); } // Check if it is allowed to update the field. if (!$parent->get($parent_field_name)->access('edit')) { return AccessResult::forbidden('No edit access to the paragraph field.'); } // By default, paragraph reference fields do not support translations. For // this reason we need to check in case the parent entity is translatable // that current translation is the default one and that the paragraph Loading Loading @@ -307,6 +319,10 @@ class ParagraphsHelper implements ParagraphsHelperInterface { return FALSE; } $parent_field_name = $paragraph->get('parent_field_name')->value; // Check if it is allowed to edit the given field. if (!$parent->get($parent_field_name)->access('edit')) { return FALSE; } $paragraph_items = $parent->get($parent_field_name)->getValue(); if ($operation == 'up') { foreach ($paragraph_items as $delta => $paragraph_item) { Loading Loading @@ -350,6 +366,10 @@ class ParagraphsHelper implements ParagraphsHelperInterface { public function delete(ParagraphInterface $paragraph) { $parent_field_name = $paragraph->get('parent_field_name')->value; $parent_entity = $paragraph->getParentEntity(); // Check if it is allowed to edit the given field. if (!$parent_entity->get($parent_field_name)->access('edit')) { return FALSE; } $items = $parent_entity->get($parent_field_name); $items->filter(function (TypedDataInterface $item) use ($paragraph) { if ($item->target_id == $paragraph->id()) { Loading Loading
frontend_editing.module +9 −2 Changes for frontend_editing.module: 9 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -310,8 +310,15 @@ function frontend_editing_entity_view_alter(&$build, EntityInterface $entity, En ]; if ($entity->getEntityType()->hasKey('bundle')) { $build['frontend_editing']['common_actions']['title_edit']['title'] = [ '#markup' => '<span class="action-title">' . $entity->get($entity->getEntityType() ->getKey('bundle'))->entity->label() . '</span>', '#type' => 'html_tag', '#tag' => 'span', '#attributes' => [ 'class' => ['action-title'], ], 'label' => [ '#plain_text' => $entity->get($entity->getEntityType() ->getKey('bundle'))->entity->label(), ], ]; } // Add the edit link. Loading
frontend_editing.routing.yml +3 −0 Changes for frontend_editing.routing.yml: 3 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -74,6 +74,7 @@ frontend_editing.paragraph_delete: _controller: '\Drupal\frontend_editing\Controller\FrontendEditingController::delete' requirements: _custom_access: '\Drupal\frontend_editing\Controller\FrontendEditingController::accessDelete' _csrf_token: 'TRUE' options: parameters: paragraph: Loading @@ -86,6 +87,7 @@ frontend_editing.paragraph_up: _controller: '\Drupal\frontend_editing\Controller\FrontendEditingController::up' requirements: _custom_access: '\Drupal\frontend_editing\Controller\FrontendEditingController::accessUp' _csrf_token: 'TRUE' options: parameters: paragraph: Loading @@ -98,6 +100,7 @@ frontend_editing.paragraph_down: _controller: '\Drupal\frontend_editing\Controller\FrontendEditingController::down' requirements: _custom_access: '\Drupal\frontend_editing\Controller\FrontendEditingController::accessDown' _csrf_token: 'TRUE' options: parameters: paragraph: Loading
src/ParagraphsHelper.php +20 −0 Changes for src/ParagraphsHelper.php: 20 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -145,6 +145,10 @@ class ParagraphsHelper implements ParagraphsHelperInterface { if (!$parent_entity || !$parent_entity->access('update') || !$parent_entity->hasField($parent_field_name)) { return AccessResult::forbidden(); } // Check if it is allowed to update the field / add new paragraphs. if (!$parent_entity->get($parent_field_name)->access('edit')) { return AccessResult::forbidden('No edit access to the paragraph field.'); } // Check that the given paragraphs type is allowed. $parent_field_definition = $parent_entity->get($parent_field_name)->getFieldDefinition(); if ($parent_entity->isTranslatable() && !$parent_entity->isDefaultTranslation() && !$parent_field_definition->isTranslatable()) { Loading Loading @@ -217,6 +221,10 @@ class ParagraphsHelper implements ParagraphsHelperInterface { if (!$parent->hasField($parent_field_name) || $parent->get($parent_field_name)->isEmpty()) { return AccessResult::forbidden(); } // Check if it is allowed to update the field. if (!$parent->get($parent_field_name)->access('edit')) { return AccessResult::forbidden('No edit access to the paragraph field.'); } // By default, paragraph reference fields do not support translations. For // this reason we need to check in case the parent entity is translatable // that current translation is the default one and that the paragraph field Loading Loading @@ -275,6 +283,10 @@ class ParagraphsHelper implements ParagraphsHelperInterface { if (!$parent->hasField($parent_field_name) || $parent->get($parent_field_name)->isEmpty()) { return AccessResult::forbidden(); } // Check if it is allowed to update the field. if (!$parent->get($parent_field_name)->access('edit')) { return AccessResult::forbidden('No edit access to the paragraph field.'); } // By default, paragraph reference fields do not support translations. For // this reason we need to check in case the parent entity is translatable // that current translation is the default one and that the paragraph Loading Loading @@ -307,6 +319,10 @@ class ParagraphsHelper implements ParagraphsHelperInterface { return FALSE; } $parent_field_name = $paragraph->get('parent_field_name')->value; // Check if it is allowed to edit the given field. if (!$parent->get($parent_field_name)->access('edit')) { return FALSE; } $paragraph_items = $parent->get($parent_field_name)->getValue(); if ($operation == 'up') { foreach ($paragraph_items as $delta => $paragraph_item) { Loading Loading @@ -350,6 +366,10 @@ class ParagraphsHelper implements ParagraphsHelperInterface { public function delete(ParagraphInterface $paragraph) { $parent_field_name = $paragraph->get('parent_field_name')->value; $parent_entity = $paragraph->getParentEntity(); // Check if it is allowed to edit the given field. if (!$parent_entity->get($parent_field_name)->access('edit')) { return FALSE; } $items = $parent_entity->get($parent_field_name); $items->filter(function (TypedDataInterface $item) use ($paragraph) { if ($item->target_id == $paragraph->id()) { Loading