/**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('entity_test_rev');
     $this->installEntitySchema('user');
     $field_name = 'test';
     $this->fieldStorage = FieldStorageConfig::create(['field_name' => $field_name, 'entity_type' => 'entity_test_rev', 'type' => 'string', 'cardinality' => 1]);
     $this->fieldStorage->save();
     $this->field = FieldConfig::create(['field_name' => $field_name, 'entity_type' => 'entity_test_rev', 'bundle' => 'entity_test_rev', 'required' => TRUE]);
     $this->field->save();
     // Create an entity with field data.
     $this->entity = EntityTestRev::create(['user_id' => mt_rand(1, 10), 'name' => $this->randomMachineName(), $field_name => $this->randomString()]);
     $this->entity->save();
 }
Beispiel #2
0
 /**
  * @covers ::getCacheMaxAge
  * @covers ::mergeCacheMaxAge
  */
 public function testCacheMaxAge()
 {
     // Cache max age is permanent by default.
     $this->assertEquals(Cache::PERMANENT, $this->entity->getCacheMaxAge());
     // Set two cache max ages, the lower value is the one that needs to be
     // returned.
     $this->entity->mergeCacheMaxAge(600);
     $this->entity->mergeCacheMaxAge(1800);
     $this->assertEquals(600, $this->entity->getCacheMaxAge());
 }
 function setUp()
 {
     parent::setUp();
     $this->field_name = 'test_options';
     entity_create('field_storage_config', array('name' => $this->field_name, 'entity_type' => 'entity_test_rev', 'type' => 'list_text', 'cardinality' => 1, 'settings' => array('allowed_values_function' => 'options_test_dynamic_values_callback')))->save();
     $this->instance = entity_create('field_instance_config', array('field_name' => $this->field_name, 'entity_type' => 'entity_test_rev', 'bundle' => 'entity_test_rev', 'required' => TRUE))->save();
     entity_get_form_display('entity_test_rev', 'entity_test_rev', 'default')->setComponent($this->field_name, array('type' => 'options_select'))->save();
     // Create an entity and prepare test data that will be used by
     // options_test_dynamic_values_callback().
     $values = array('user_id' => mt_rand(1, 10), 'name' => $this->randomMachineName());
     $this->entity = entity_create('entity_test_rev', $values);
     $this->entity->save();
     $this->test = array('label' => $this->entity->label(), 'uuid' => $this->entity->uuid(), 'bundle' => $this->entity->bundle(), 'uri' => $this->entity->url());
 }
 protected function setUp()
 {
     parent::setUp();
     $field_name = 'test_options';
     $this->fieldStorage = FieldStorageConfig::create(['field_name' => $field_name, 'entity_type' => 'entity_test_rev', 'type' => 'list_string', 'cardinality' => 1, 'settings' => ['allowed_values_function' => 'options_test_dynamic_values_callback']]);
     $this->fieldStorage->save();
     $this->field = FieldConfig::create(['field_name' => $field_name, 'entity_type' => 'entity_test_rev', 'bundle' => 'entity_test_rev', 'required' => TRUE])->save();
     entity_get_form_display('entity_test_rev', 'entity_test_rev', 'default')->setComponent($field_name, ['type' => 'options_select'])->save();
     // Create an entity and prepare test data that will be used by
     // options_test_dynamic_values_callback().
     $values = ['user_id' => mt_rand(1, 10), 'name' => $this->randomMachineName()];
     $this->entity = EntityTestRev::create($values);
     $this->entity->save();
     $this->test = ['label' => $this->entity->label(), 'uuid' => $this->entity->uuid(), 'bundle' => $this->entity->bundle(), 'uri' => $this->entity->url()];
 }
Beispiel #5
0
 /**
  * {@inheritdoc}
  */
 public function save()
 {
     $return = parent::save();
     $this->trustedData = FALSE;
     return $return;
 }
 /**
  * {@inheritdoc}
  */
 public function link($text = NULL, $rel = 'edit-form', array $options = [])
 {
     return parent::link($text, $rel, $options);
 }
 /**
  * {@inheritdoc}
  */
 public function __sleep()
 {
     // Get the values of instantiated field objects, only serialize the values.
     foreach ($this->fields as $name => $fields) {
         foreach ($fields as $langcode => $field) {
             $this->values[$name][$langcode] = $field->getValue();
         }
     }
     $this->fields = array();
     $this->fieldDefinitions = NULL;
     $this->languages = NULL;
     $this->clearTranslationCache();
     return parent::__sleep();
 }
 /**
  * {@inheritdoc}
  */
 public function url($rel = 'edit-form', $options = array())
 {
     return parent::url($rel, $options);
 }
Beispiel #9
0
 /**
  * {@inheritdoc}
  */
 public static function preDelete(EntityStorageInterface $storage, array $entities)
 {
     parent::preDelete($storage, $entities);
     foreach ($entities as $entity) {
         if ($entity->isUninstalling() || $entity->isSyncing()) {
             // During extension uninstall and configuration synchronization
             // deletions are already managed.
             break;
         }
         // Fix or remove any dependencies.
         $config_entities = static::getConfigManager()->getConfigEntitiesToChangeOnDependencyRemoval('config', [$entity->getConfigDependencyName()], FALSE);
         /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $dependent_entity */
         foreach ($config_entities['update'] as $dependent_entity) {
             $dependent_entity->save();
         }
         foreach ($config_entities['delete'] as $dependent_entity) {
             $dependent_entity->delete();
         }
     }
 }
Beispiel #10
0
 /**
  * {@inheritdoc}
  */
 public static function postLoad(EntityStorageInterface $storage, array &$entities)
 {
     parent::postLoad($storage, $entities);
     $routes = array();
     foreach ($entities as $menu_link) {
         $menu_link->options = unserialize($menu_link->options);
         $menu_link->route_parameters = unserialize($menu_link->route_parameters);
         // By default use the menu_name as type.
         $menu_link->bundle = $menu_link->menu_name;
         // For all links that have an associated route, load the route object now
         // and save it on the object. That way we avoid a select N+1 problem later.
         if ($menu_link->route_name) {
             $routes[$menu_link->id()] = $menu_link->route_name;
         }
     }
     // Now mass-load any routes needed and associate them.
     if ($routes) {
         $route_objects = \Drupal::service('router.route_provider')->getRoutesByNames($routes);
         foreach ($routes as $entity_id => $route) {
             // Not all stored routes will be valid on load.
             if (isset($route_objects[$route])) {
                 $entities[$entity_id]->setRouteObject($route_objects[$route]);
             }
         }
     }
 }
Beispiel #11
0
 /**
  * @covers ::referencedEntities
  */
 public function testReferencedEntities()
 {
     $this->assertSame(array(), $this->entity->referencedEntities());
 }