/** * {@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; }
/** * {@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; }
public function setUp() { $this->account = $this->prophesize(AccountInterface::class); $this->contextHandler = $this->prophesize(ContextHandlerInterface::class); $this->uuidGenerator = $this->prophesize(UuidInterface::class); $this->token = $this->prophesize(Token::class); $this->builderManager = $this->prophesize(DisplayBuilderManagerInterface::class); $this->layoutManager = $this->prophesize(LayoutPluginManagerInterface::class); $this->layout = $this->prophesize(LayoutInterface::class); $this->layoutManager->createInstance(Argument::type('string'), Argument::type('array'))->willReturn($this->layout->reveal()); $this->variant = new PanelsDisplayVariant([], '', [], $this->contextHandler->reveal(), $this->account->reveal(), $this->uuidGenerator->reveal(), $this->token->reveal(), $this->builderManager->reveal(), $this->layoutManager->reveal()); }
/** * {@inheritdoc} */ public function getUuid() { if (empty($this->uuid)) { $this->uuid = $this->uuidGenerator->generate(); } return $this->uuid; }
/** * {@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; }
/** * @covers ::create * @covers ::doCreate * * @return \Drupal\Core\Entity\EntityInterface */ public function testCreate() { $this->cacheTagsInvalidator->expects($this->never())->method('invalidateTags'); $this->moduleHandler->expects($this->at(0))->method('invokeAll')->with('test_entity_type_create'); $this->moduleHandler->expects($this->at(1))->method('invokeAll')->with('entity_create'); $this->uuidService->expects($this->once())->method('generate')->will($this->returnValue('bar')); $entity = $this->entityStorage->create(array('id' => 'foo')); $this->assertInstanceOf('Drupal\\Core\\Entity\\EntityInterface', $entity); $this->assertSame('foo', $entity->id()); $this->assertSame('bar', $entity->uuid()); return $entity; }
/** * @covers ::create * @covers ::doCreate * * @return \Drupal\Core\Entity\EntityInterface */ public function testCreate() { $entity = $this->getMockEntity('Drupal\\Core\\Entity\\Entity', array(), array('toArray')); $this->entityType->expects($this->once())->method('getClass')->will($this->returnValue(get_class($entity))); $this->setUpKeyValueEntityStorage(); $this->moduleHandler->expects($this->at(0))->method('invokeAll')->with('test_entity_type_create'); $this->moduleHandler->expects($this->at(1))->method('invokeAll')->with('entity_create'); $this->uuidService->expects($this->once())->method('generate')->will($this->returnValue('bar')); $entity = $this->entityStorage->create(array('id' => 'foo')); $this->assertInstanceOf('Drupal\\Core\\Entity\\EntityInterface', $entity); $this->assertSame('foo', $entity->id()); $this->assertSame('bar', $entity->uuid()); return $entity; }
/** * {@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; }
/** * @covers ::createDuplicate */ public function testCreateDuplicate() { $this->entityType->expects($this->at(0))->method('getKey')->with('id')->will($this->returnValue('id')); $this->entityType->expects($this->at(1))->method('hasKey')->with('uuid')->will($this->returnValue(TRUE)); $this->entityType->expects($this->at(2))->method('getKey')->with('uuid')->will($this->returnValue('uuid')); $new_uuid = '8607ef21-42bc-4913-978f-8c06207b0395'; $this->uuid->expects($this->once())->method('generate')->will($this->returnValue($new_uuid)); $duplicate = $this->entity->createDuplicate(); $this->assertInstanceOf('\\Drupal\\Core\\Entity\\Entity', $duplicate); $this->assertNotSame($this->entity, $duplicate); $this->assertFalse($this->entity->isNew()); $this->assertTrue($duplicate->isNew()); $this->assertNull($duplicate->id()); $this->assertNull($duplicate->getOriginalId()); $this->assertNotEquals($this->entity->uuid(), $duplicate->uuid()); $this->assertSame($new_uuid, $duplicate->uuid()); }
/** * {@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); }
/** * 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))); }