/** * Builds a table row for overview form. * * @param \Drupal\Core\Config\Entity\ConfigEntityInterface $entity * Data needed to build the list row. * * @return array * A single table row for the overview. */ public function overviewRow(ConfigEntityInterface $entity) { $label = $entity->label() ?: $this->t('@type: @id', array('@type' => $entity->getEntityTypeId(), '@id' => $entity->id())); // Get current job items for the entity to determine translation statuses. $source_lang = $entity->language()->getId(); $current_job_items = tmgmt_job_item_load_latest('config', $entity->getEntityTypeId(), $entity->getConfigDependencyName(), $source_lang); $row['id'] = $entity->id(); $definition = \Drupal::entityTypeManager()->getDefinition($entity->bundle()); $row['config_id'] = $definition->getConfigPrefix() . '.' . $entity->id(); if ($entity->hasLinkTemplate('edit-form')) { $row['title'] = $entity->toLink($label, 'edit-form'); } else { // If the entity doesn't have a link we display a label. $row['title'] = $label; } // Load entity translation specific data. foreach (\Drupal::languageManager()->getLanguages() as $langcode => $language) { $translation_status = 'current'; if ($langcode == $source_lang) { $translation_status = 'original'; } elseif (!$this->isTranslated($langcode, $entity->getConfigDependencyName())) { $translation_status = 'missing'; } // @todo Find a way to support marking configuration translations as outdated. $build = $this->buildTranslationStatus($translation_status, isset($current_job_items[$langcode]) ? $current_job_items[$langcode] : NULL); $row['langcode-' . $langcode] = ['data' => \Drupal::service('renderer')->render($build), 'class' => array('langstatus-' . $langcode)]; } return $row; }
/** * Creates an event entity. * * @param \Drupal\Core\Config\Entity\ConfigEntityInterface * An entity type. * @param array $settings * Additional settings for the new entity. * * @return \Drupal\Core\Entity\EntityInterface * An event. */ function createEntity(ConfigEntityInterface $entity_type, $settings = []) { // @todo change to custom entity $entity = $this->drupalCreateNode(['type' => $entity_type->id()] + $settings); return $entity; }
/** * @covers ::save * @covers ::doSave * * @depends testSaveInsert */ public function testSaveRename(ConfigEntityInterface $entity) { $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->exactly(1))->method('setData'); $config_object->expects($this->once())->method('save'); $config_object->expects($this->atLeastOnce())->method('get')->willReturn([]); $this->cacheTagsInvalidator->expects($this->once())->method('invalidateTags')->with(array($this->entityTypeId . '_list')); $this->configFactory->expects($this->once())->method('rename')->willReturn($this->configFactory); $this->configFactory->expects($this->exactly(1))->method('getEditable')->with('the_config_prefix.bar')->will($this->returnValue($config_object)); $this->configFactory->expects($this->exactly(2))->method('loadMultiple')->with(array('the_config_prefix.foo'))->will($this->returnValue(array())); $this->configFactory->expects($this->once())->method('get')->with('the_config_prefix.foo')->will($this->returnValue($config_object)); // Performing a rename does not change the original ID until saving. $this->assertSame('foo', $entity->getOriginalId()); $entity->set('id', 'bar'); $this->assertSame('foo', $entity->getOriginalId()); $this->entityQuery->expects($this->once())->method('condition')->with('uuid', 'bar')->will($this->returnSelf()); $this->entityQuery->expects($this->once())->method('execute')->will($this->returnValue(array($entity->id()))); $return = $this->entityStorage->save($entity); $this->assertSame(SAVED_UPDATED, $return); $this->assertSame('bar', $entity->getOriginalId()); }
/** * {@inheritdoc} */ public function getBaseRouteParameters() { return array($this->entityType => $this->entity->id()); }