-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathParagraphsSimpleEditController.php
More file actions
executable file
·89 lines (73 loc) · 3.26 KB
/
ParagraphsSimpleEditController.php
File metadata and controls
executable file
·89 lines (73 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
namespace Drupal\paragraphs_simple_edit\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessResult;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\Request;
/**
* Controller for showing a Paragraph add form targeted to a host entity.
*/
class ParagraphsSimpleEditController extends ControllerBase {
/**
* Show paragraph add form.
*/
public function add($root_parent_type, $root_parent, $bundle, Request $request) {
// Load host entity storage and the host entity itself.
// $entity_storage = $this->entityTypeManager->getStorage($host_entity_type);
// if (!$entity_storage) {
// throw new NotFoundHttpException("Unknown host entity type: $host_entity_type");
// }
// $host = $entity_storage->load($host_entity);
// if (!$host) {
// throw new NotFoundHttpException("Host entity not found: $host_entity_type $host_entity");
// }
// // Ensure the current user can view the host (basic protection).
// if (!$host->access('view')) {
// throw new NotFoundHttpException("Host entity not accessible.");
// }
// Create a paragraph entity of the requested bundle (unsaved).
//$paragraph_storage = $this->entityTypeManager->getStorage('paragraph');
// if (!$paragraph_storage) {
// // Paragraph module not enabled or entity type missing.
// throw new NotFoundHttpException("Paragraph entity type is not available on this site.");
// }
//$paragraph = $paragraph_storage->create(['type' => $paragraph_type]);
// Access check: can current user create this paragraph bundle?
// if (!$paragraph->access('create')) {
// // Use access denied rather than 404 if you prefer.
// return $this->accessDenied();
// }
// OPTIONAL / HELPFUL: If you want the paragraph form to know which host it
// will be attached to (so you can attach in the save path), you can add
// these as form state values or as query parameters. Here we inject them
// as #attached form build info (a small, non-invasive approach):
//
// The form can read these values in a hook_form_alter or in a custom form
// submit handler.
// $paragraph->parent_type = $host_entity_type;
// $paragraph->parent_id = $host_entity;
// Render and return the paragraph entity add form.
// Use the standard entity form builder. We present the default form mode.
//$form = $this->entityFormBuilder->getForm($paragraph, 'add');
// Attach the host info as a hidden form element so submit handlers can
// pick it up easily. We must alter the built form structure here.
// Only add if form is an array and not cached markup.
// if (is_array($form)) {
// $form['#cache']['contexts'][] = 'user'; // conservative cache context
// // Add hidden values for downstream submit handlers.
// $form['mymodule_host_info'] = [
// '#type' => 'value',
// '#value' => [
// 'host_entity_type' => $host_entity_type,
// 'host_entity_id' => $host_entity,
// ],
// ];
// }
$form['test'] = [
'#markup' => 'test',
];
return $form;
}
}