Paragraphs Editor
CommandContextInterface.php
Go to the documentation of this file.
1 <?php
2 
4 
5 /**
6  * Provides an interface for paragraph command context.
7  *
8  * A context object wraps all the information you need to know about a
9  * paragraphs ckeditor command that is being executed, including:
10  * - The parent entity that the command is being performed on.
11  * - The field configuration for the field the command is being performed on.
12  * - The allowed paragraph bundles for the field.
13  * - The edit buffer associated with the editor instance.
14  * - The plugins associated with the editor instance.
15  * - The field widget settings for the editor instance.
16  * - Any additional context provided by the route.
17  */
19 
20  /**
21  * Gets the entity that the field belongs to.
22  *
23  * @return \Drupal\Core\Entity\EntityInterface
24  * The entity that contains the field being edited.
25  */
26  public function getEntity();
27 
28  /**
29  * Gets the field configuration for the field being edited.
30  *
31  * @return \Drupal\Core\Field\FieldConfigInterface
32  * The field configuration object for the field being edited.
33  */
34  public function getFieldConfig();
35 
36  /**
37  * Gets a filter object for determining allowed paragraph bundles.
38  *
39  * @return \Drupal\paragraphs_editor\EditorCommand\ParagraphBundleFilterInterface
40  * A filter object for getting information about allowed bundles.
41  */
42  public function getBundleFilter();
43 
44  /**
45  * Gets the edit buffer for the editor instance.
46  *
47  * @return \Drupal\paragraphs_editor\EditBuffer\EditBufferInterface
48  * The edit buffer associated with the editor instance that command pertains
49  * to.
50  */
51  public function getEditBuffer();
52 
53  /**
54  * Gets the context string that uniquely identifies the editor instance.
55  *
56  * @return string
57  * A string containing the parent node type, parent node id, field instance
58  * id, and a unique random string to identify the instance.
59  */
60  public function getContextString();
61 
62  /**
63  * Gets the random build id for this context.
64  *
65  * @return string
66  * The random build id associated with the context.
67  */
68  public function getBuildId();
69 
70  /**
71  * Set a temporary value for the duration of command execution.
72  *
73  * @param string $name
74  * The key name for the temporary value.
75  * @param mixed $value
76  * The temporary value to store.
77  */
78  public function setTemporary($name, $value);
79 
80  /**
81  * Gets a temporary value.
82  *
83  * @param string $name
84  * The key name for the temporary value.
85  */
86  public function getTemporary($name);
87 
88  /**
89  * Returns whether or not a context is valid.
90  *
91  * @return bool
92  * TRUE if the context is valid, FALSE otherwise.
93  */
94  public function isValid();
95 
96  /**
97  * Associates a plugin with the command context.
98  *
99  * @param string $type
100  * The plugin type. This can be either 'bundle_selector' or
101  * 'delivery_provider'.
102  * @param object $plugin_object
103  * The plugin to associate.
104  */
105  public function setPlugin($type, $plugin_object);
106 
107  /**
108  * Gets the plugin associated with the context.
109  *
110  * @param string $type
111  * The plugin type to retrieve. This can be either 'bundle_selector' or
112  * 'delivery_provider'.
113  *
114  * @return object
115  * The requested plugin object if it exists, NULL otherwise.
116  */
117  public function getPlugin($type);
118 
119  /**
120  * Gets a field widget setting.
121  *
122  * @param string $name
123  * The field widget setting to retrieve.
124  *
125  * @return mixed
126  * The value of the setting or NULL if no such setting is found.
127  */
128  public function getSetting($name);
129 
130  /**
131  * Gets all the field widget settings.
132  *
133  * @return array
134  * The field widget settings associated with the editor instance.
135  */
136  public function getSettings();
137 
138  /**
139  * Creates a url object for the specified commands.
140  *
141  * @param string $command
142  * The name of a command to create a url for.
143  * @param array $params
144  * An optional array of query parameters to add to the Url object.
145  *
146  * @return \Drupal\Core\Url
147  * The Drupal url object pertaining to the command.
148  */
149  public function createCommandUrl($command, array $params = []);
150 
151  /**
152  * Adds additional context about the command.
153  *
154  * @param string $key
155  * The name of the context to add.
156  * @param mixed $value
157  * The value of the context to add.
158  */
159  public function addAdditionalContext($key, $value);
160 
161  /**
162  * Gets additional context about the command.
163  *
164  * @param string|null $key
165  * The name of the context to get.
166  *
167  * @return mixed
168  * The value associated with $key or an array of all values if $key is NULL.
169  */
170  public function getAdditionalContext($key = NULL);
171 
172 }