/** * @covers ::calculateDependencies */ public function testCalculateDependenciesWithEntityBundle() { $target_entity_type_id = $this->randomMachineName(16); $target_entity_type = $this->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface'); $target_entity_type->expects($this->any())->method('getProvider')->will($this->returnValue('test_module')); $bundle_id = $this->randomMachineName(10); $values = array('targetEntityType' => $target_entity_type_id, 'bundle' => $bundle_id); $target_entity_type->expects($this->any())->method('getBundleConfigDependency')->will($this->returnValue(array('type' => 'config', 'name' => 'test_module.type.' . $bundle_id))); $this->entityManager->expects($this->at(0))->method('getDefinition')->with($target_entity_type_id)->will($this->returnValue($target_entity_type)); $this->entityManager->expects($this->at(1))->method('getDefinition')->with($this->entityTypeId)->will($this->returnValue($this->entityType)); $entity = new RdfMapping($values, $this->entityTypeId); $dependencies = $entity->calculateDependencies()->getDependencies(); $this->assertContains('test_module.type.' . $bundle_id, $dependencies['config']); $this->assertContains('test_module', $dependencies['module']); }
/** * Create fields for the selected properties. */ protected function createField() { $entity_type = 'node'; $bundle = $this->entity->id(); foreach ($this->properties as $key => $value) { $label = $this->converter->label($key); // Add the field prefix and truncate if longer than 32 char. $field_name = $this->prefix . strtolower($label); if (strlen($field_name) > 32) { $field_name = substr($field_name, 0, 32); } $field_storage = array( 'field_name' => $field_name, 'entity_type' => $entity_type, 'type' => $value['type'], 'translatable' => TRUE, ); $instance = array( 'field_name' => $field_name, 'entity_type' => $entity_type, 'bundle' => $bundle, 'label' => $label, // Field translatability should be explicitly enabled by the users. 'translatable' => FALSE, ); // Create the field and instance. try { \Drupal::entityTypeManager()->getStorage('field_storage_config')->create($field_storage)->save(); \Drupal::entityTypeManager()->getStorage('field_config')->create($instance)->save(); // Make sure the field is displayed in the 'default' form mode (using // default widget and settings). It stays hidden for other form modes // until it is explicitly configured. entity_get_form_display($entity_type, $bundle, 'default') ->setComponent($field_name) ->save(); // Make sure the field is displayed in the 'default' view mode (using // default formatter and settings). It stays hidden for other view // modes until it is explicitly configured. entity_get_display($entity_type, $bundle, 'default') ->setComponent($field_name) ->save(); // RDF Mapping. $this->rdfMapping->setFieldMapping($field_name, array( 'properties' => array($key), ) ); } catch (\Exception $e) { drupal_set_message($this->t('There was a problem creating field %label: !message', array( '%label' => $instance['label'], '!message' => $e->getMessage(), )), 'error'); } } }