Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function createInstance($plugin_id, array $configuration = [])
 {
     $instance = parent::createInstance($plugin_id, $configuration);
     // Make sure that the instance has a UUID and generate one if necessary.
     if (!$instance->getUuid()) {
         $instance->setUuid($this->uuidService->generate());
     }
     return $instance;
 }
 /**
  * {@inheritdoc}
  */
 public function addExpressionObject(ExpressionInterface $expression, $return_uuid = FALSE)
 {
     if (!$expression instanceof ConditionExpressionInterface) {
         throw new InvalidExpressionException();
     }
     $uuid = $this->uuidService->generate();
     $this->conditions[$uuid] = $expression;
     return $return_uuid ? $uuid : $this;
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function getUuid()
 {
     if (empty($this->uuid)) {
         $this->uuid = $this->uuidGenerator->generate();
     }
     return $this->uuid;
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  *
  * Passes the $parentZone along to the instantiated plugin.
  */
 public function createInstance($pluginId, array $configuration = [], ZoneInterface $parentZone = NULL)
 {
     $pluginDefinition = $this->getDefinition($pluginId);
     $pluginDefinition['parent_zone'] = $parentZone;
     $plugin_class = DefaultFactory::getPluginClass($pluginId, $pluginDefinition);
     // Generate an id for the plugin instance, if it wasn't provided.
     if (empty($configuration['id'])) {
         $configuration['id'] = $this->uuidService->generate();
     }
     // If the plugin provides a factory method, pass the container to it.
     if (is_subclass_of($plugin_class, 'Drupal\\Core\\Plugin\\ContainerFactoryPluginInterface')) {
         $plugin = $plugin_class::create(\Drupal::getContainer(), $configuration, $pluginId, $pluginDefinition, $parentZone);
     } else {
         $plugin = new $plugin_class($configuration, $pluginId, $pluginDefinition, $parentZone);
     }
     return $plugin;
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function create(array $values = array())
 {
     $entity_class = $this->entityClass;
     $entity_class::preCreate($this, $values);
     // Assign a new UUID if there is none yet.
     if ($this->uuidKey && $this->uuidService && !isset($values[$this->uuidKey])) {
         $values[$this->uuidKey] = $this->uuidService->generate();
     }
     $entity = $this->doCreate($values);
     $entity->enforceIsNew();
     $entity->postCreate($this);
     // Modules might need to add or change the data initially held by the new
     // entity object, for instance to fill-in default values.
     $this->invokeHook('create', $entity);
     return $entity;
 }
Exemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function submitFeedForm(array &$form, FormStateInterface $form_state, FeedInterface $feed)
 {
     // We need to store this for later so that we have the feed id.
     $new_fid = reset($form_state->getValue('source'));
     $feed_config = $feed->getConfigurationFor($this);
     // Generate a UUID that maps to this feed for file usage. We can't depend
     // on the feed id since this could be called before an id is assigned.
     $feed_config['usage_id'] = $feed_config['usage_id'] ?: $this->uuid->generate();
     if ($new_fid == $feed_config['fid']) {
         return;
     }
     $this->deleteFile($feed_config['fid'], $feed_config['usage_id']);
     if ($new_fid) {
         $file = $this->fileStorage->load($new_fid);
         $this->fileUsage->add($file, 'feeds', $this->pluginType(), $feed_config['usage_id']);
         $file->setPermanent();
         $file->save();
         $feed_config['fid'] = $new_fid;
         $feed->setSource($file->getFileUri());
     }
     $feed->setConfigurationFor($this, $feed_config);
 }
Exemplo n.º 7
0
 /**
  * Tests that generated UUIDs are unique.
  *
  * @dataProvider providerUuidInstances
  */
 public function testUuidIsUnique(UuidInterface $instance)
 {
     $this->assertNotEquals($instance->generate(), $instance->generate(), sprintf('Same UUID was not generated twice with %s.', get_class($instance)));
 }