/**
  * {@inheritdoc}
  */
 public function save(EntityInterface $entity)
 {
     $return = parent::save($entity);
     // Update the state of registered events.
     // @todo Should we trigger a container rebuild here as well? Might be a bit
     // expensive on every save?
     $this->stateService->set('rules.registered_events', $this->getRegisteredEvents());
     return $return;
 }
 /**
  * @covers ::save()
  * @covers ::doSave()
  *
  * @expectedException \Drupal\Core\Config\ConfigDuplicateUUIDException
  * @expectedExceptionMessage when this entity already exists with UUID
  */
 public function testSaveChangedUuid()
 {
     $config_object = $this->getMockBuilder('Drupal\\Core\\Config\\Config')->disableOriginalConstructor()->getMock();
     $config_object->expects($this->atLeastOnce())->method('isNew')->will($this->returnValue(FALSE));
     $config_object->expects($this->never())->method('save');
     $config_object->expects($this->exactly(2))->method('get')->will($this->returnValueMap(array(array('', array('id' => 'foo')), array('id', 'foo'))));
     $this->cacheBackend->expects($this->never())->method('invalidateTags');
     $this->configFactory->expects($this->at(1))->method('loadMultiple')->with(array('the_config_prefix.foo'))->will($this->returnValue(array()));
     $this->configFactory->expects($this->at(2))->method('loadMultiple')->with(array('the_config_prefix.foo'))->will($this->returnValue(array($config_object)));
     $this->configFactory->expects($this->once())->method('get')->with('the_config_prefix.foo')->will($this->returnValue($config_object));
     $this->configFactory->expects($this->never())->method('rename')->will($this->returnValue($config_object));
     $this->moduleHandler->expects($this->exactly(2))->method('getImplementations')->will($this->returnValue(array()));
     $this->entityQuery->expects($this->once())->method('condition')->will($this->returnSelf());
     $this->entityQuery->expects($this->once())->method('execute')->will($this->returnValue(array('foo')));
     $entity = $this->getMockEntity(array('id' => 'foo'));
     $entity->set('uuid', 'baz');
     $this->entityStorage->save($entity);
 }
 /**
  * {@inheritdoc}
  */
 public function save(EntityInterface $entity)
 {
     // We need to get the registered events before the rule is saved, in order
     // to be able to check afterwards if we need to rebuild the container or
     // not.
     $events_before = $this->getRegisteredEvents();
     $return = parent::save($entity);
     // Update the state of registered events.
     $this->stateService->set('rules.registered_events', $this->getRegisteredEvents());
     // After the reaction rule is saved, we need to rebuild the container,
     // otherwise the reaction rule will not fire. However, we can do an
     // optimization: if every event was already registered before, we do not
     // have to rebuild the container.
     foreach ($entity->getEventNames() as $event_name) {
         if (empty($events_before[$event_name])) {
             $this->drupalKernel->rebuildContainer();
             break;
         }
     }
     return $return;
 }