コード例 #1
0
 /**
  * Creates a test subject node, with translation.
  */
 protected function setUpNode()
 {
     /** @var \Drupal\node\Entity\Node $node */
     $node = entity_create('node', array('title' => $this->randomMachineName(), 'type' => 'article', 'description' => array('value' => $this->randomMachineName(), 'format' => 'basic_html'), $this->termFieldName => array(array('target_id' => $this->term->id())), 'langcode' => $this->baseLangcode));
     $node->save();
     $node->addTranslation($this->translateToLangcode, $node->toArray());
     $node->save();
     $this->node = $node;
 }
コード例 #2
0
 /**
  * Builds an individual term item for the term item list depending on the formatter.
  *
  * @param \Drupal\taxonomy\Entity\Term $term
  * @return string
  */
 private function buildTermListItem(Term $term, $formatter)
 {
     if ($formatter === 'linked') {
         $link_url = Url::fromRoute('entity.taxonomy_term.canonical', array('taxonomy_term' => $term->id()));
         return \Drupal::l($term->label(), $link_url);
     }
     return HTML::escape($term->label());
 }
コード例 #3
0
 public function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('taxonomy_term');
     $vocabulary = entity_create('taxonomy_vocabulary', array('name' => $this->randomName(), 'vid' => drupal_strtolower($this->randomName()), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
     $vocabulary->save();
     entity_create('field_storage_config', array('name' => $this->fieldName, 'entity_type' => 'entity_test', 'type' => 'taxonomy_term_reference', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, 'settings' => array('allowed_values' => array(array('vocabulary' => $vocabulary->id(), 'parent' => 0)))))->save();
     entity_create('field_instance_config', array('entity_type' => 'entity_test', 'field_name' => $this->fieldName, 'bundle' => 'entity_test'))->save();
     $this->term = entity_create('taxonomy_term', array('name' => $this->randomName(), 'vid' => $vocabulary->id(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
     $this->term->save();
     // Add the mapping.
     $mapping = rdf_get_mapping('entity_test', 'entity_test');
     $mapping->setFieldMapping($this->fieldName, array('properties' => array('schema:about')))->save();
     // Set up test values.
     $this->entity = entity_create('entity_test');
     $this->entity->{$this->fieldName}->target_id = $this->term->id();
     $this->entity->save();
     $this->uri = $this->getAbsoluteUri($this->entity);
 }
コード例 #4
0
ファイル: PretCarburant.php プロジェクト: hacktm15/lapompa
 public static function getCid(Node $benzinarie, Term $tip_carburant)
 {
     return 'benzinarie:' . $benzinarie->id() . ':carburant:' . $tip_carburant->id();
 }