68 public function __construct(EntityTypeManagerInterface $entity_type_manager,
EditBufferCacheInterface $buffer_cache, EntityTypeBundleInfoInterface $bundle_info, array $plugin_managers) {
69 $this->entityTypeManager = $entity_type_manager;
70 $this->bufferCache = $buffer_cache;
71 $this->fieldConfigStorage = $entity_type_manager->getStorage(
'field_config');
72 $this->pluginManagers = $plugin_managers;
73 $this->bundleInfo = $bundle_info;
80 $context_params = explode(
':', $context_string);
81 $field_config_id = array_shift($context_params);
82 $widget_build_id = array_shift($context_params);
83 $entity_id = array_shift($context_params);
84 return [$field_config_id, $widget_build_id, $entity_id];
90 public function get($context_id) {
91 list($field_config_id, $widget_build_id, $entity_id) = $this->
parseContextString($context_id);
92 return $field_config_id && $widget_build_id ? $this->
create($field_config_id, $entity_id, [], $widget_build_id) : NULL;
98 public function create($field_config_id, $entity_id, array $settings = [], $widget_build_id = NULL, $edit_buffer_prototype = NULL) {
101 if (empty($widget_build_id)) {
111 $context_keys = [$field_config_id, $widget_build_id];
113 $entity_type = $field_config->getTargetEntityTypeId();
114 $entity_storage = $this->entityTypeManager->getStorage($entity_type);
117 $entity = $entity_storage->load($entity_id);
118 $context_keys[] = $entity_id;
124 $context_string = implode(
':', $context_keys);
125 if ($edit_buffer_prototype) {
126 $edit_buffer = $edit_buffer_prototype->createCopy($context_string);
129 $edit_buffer = $this->bufferCache->get($context_string);
132 $context =
new CommandContext($entity, $field_config, $edit_buffer, $bundle_filter, $settings);
133 $this->
attachPlugin(
'delivery_provider', $settings, $context);
134 $this->
attachPlugin(
'bundle_selector', $settings, $context);
136 catch (\Exception $e) {
150 $to = $this->
create($field_config_id, $entity_id, $settings, $widget_build_id, $from->
getEditBuffer());
151 $to->getEditBuffer()->save();
167 return isset($this->pluginManagers[$type]) ? $this->pluginManagers[$type] : NULL;
188 $plugin_name = isset($settings[$type]) ? $settings[$type] :
'';
191 'context' => $context,
204 return Crypt::randomBytesBase64();
parseContextString($context_string)
regenerate(CommandContextInterface $from)
__construct(EntityTypeManagerInterface $entity_type_manager, EditBufferCacheInterface $buffer_cache, EntityTypeBundleInfoInterface $bundle_info, array $plugin_managers)
static ensureFieldConfig(FieldDefinitionInterface $field_definition=NULL)
free(CommandContextInterface $context)
createBundleFilter(FieldConfigInterface $field_config)
setPlugin($type, $plugin_object)
create($field_config_id, $entity_id, array $settings=[], $widget_build_id=NULL, $edit_buffer_prototype=NULL)
attachPlugin($type, array $settings, CommandContextInterface $context)