当前位置: 首页>>代码示例>>PHP>>正文


PHP NodeType::id方法代码示例

本文整理汇总了PHP中Drupal\node\Entity\NodeType::id方法的典型用法代码示例。如果您正苦于以下问题:PHP NodeType::id方法的具体用法?PHP NodeType::id怎么用?PHP NodeType::id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\node\Entity\NodeType的用法示例。


在下文中一共展示了NodeType::id方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createField

  /**
   * 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');
      }
    }
  }
开发者ID:eloiv,项目名称:botafoc.cat,代码行数:63,代码来源:ContentBuilderForm.php

示例2: createReferrerEntity

 /**
  * Create the referrer entity.
  */
 protected function createReferrerEntity()
 {
     /** @var \Drupal\node\Entity\Node $node */
     $node = entity_create($this->testEntityTypeName, array('title' => $this->randomMachineName(), 'type' => $this->referrerType->id(), 'description' => array('value' => $this->randomMachineName(), 'format' => 'basic_html'), $this->referenceFieldName => array(array('target_id' => $this->referencedEntityWithTranslation->id()), array('target_id' => $this->referencedEntityWithoutTranslation->id())), 'langcode' => $this->baseLangcode));
     $node->save();
     $node->addTranslation($this->translateToLangcode, $node->toArray());
     $node->save();
     return $node;
 }
开发者ID:komejo,项目名称:article-test,代码行数:12,代码来源:EntityReferenceFieldTranslatedReferenceViewTest.php

示例3: testCustomTargetBundleDeletion

 /**
  * Tests that deletions of custom bundles are mirrored in field settings.
  */
 public function testCustomTargetBundleDeletion()
 {
     // Attach an entity reference field to $this->nodeType.
     $name = Unicode::strtolower($this->randomMachineName());
     $label = $this->randomString();
     $handler_settings = ['target_bundles' => [$this->customBundle => $this->customBundle]];
     $this->createEntityReferenceField('node', $this->nodeType->id(), $name, $label, 'entity_test', 'default', $handler_settings);
     // Check that the 'target_bundle' setting contains the custom bundle.
     $field_config = FieldConfig::loadByName('node', $this->nodeType->id(), $name);
     $actual_handler_settings = $field_config->getSetting('handler_settings');
     $this->assertEqual($handler_settings, $actual_handler_settings);
     // Delete the custom bundle.
     entity_test_delete_bundle($this->customBundle, 'entity_test');
     // Check that the deleted bundle is no longer present in the
     // 'target_bundles' field setting.
     $field_config = FieldConfig::loadByName('node', $this->nodeType->id(), $name);
     $handler_settings = $field_config->getSetting('handler_settings');
     $this->assertTrue(empty($handler_settings['target_bundles']));
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:22,代码来源:EntityReferenceSettingsTest.php

示例4: buildPermissions

 /**
  * Builds a standard list of node permissions for a given type.
  *
  * @param \Drupal\node\Entity\NodeType $type
  *   The machine name of the node type.
  *
  * @return array
  *   An array of permission names and descriptions.
  */
 protected function buildPermissions(NodeType $type)
 {
     $type_id = $type->id();
     $type_params = array('%type_name' => $type->label());
     return array("create {$type_id} content" => array('title' => $this->t('%type_name: Create new content', $type_params)), "edit own {$type_id} content" => array('title' => $this->t('%type_name: Edit own content', $type_params)), "edit any {$type_id} content" => array('title' => $this->t('%type_name: Edit any content', $type_params)), "delete own {$type_id} content" => array('title' => $this->t('%type_name: Delete own content', $type_params)), "delete any {$type_id} content" => array('title' => $this->t('%type_name: Delete any content', $type_params)), "view {$type_id} revisions" => array('title' => $this->t('%type_name: View revisions', $type_params)), "revert {$type_id} revisions" => array('title' => $this->t('%type_name: Revert revisions', $type_params), 'description' => t('Role requires permission <em>view revisions</em> and <em>edit rights</em> for nodes in question, or <em>administer nodes</em>.')), "delete {$type_id} revisions" => array('title' => $this->t('%type_name: Delete revisions', $type_params), 'description' => $this->t('Role requires permission to <em>view revisions</em> and <em>delete rights</em> for nodes in question, or <em>administer nodes</em>.')));
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:15,代码来源:NodePermissions.php

示例5: buildPermissions

 /**
  * Returns a list of view unpublished permissions for a given node type.
  *
  * @param \Drupal\node\Entity\NodeType $type
  *   The node type.
  *
  * @return array
  *   An associative array of permission names and descriptions.
  */
 protected function buildPermissions(NodeType $type)
 {
     $type_id = $type->id();
     $type_params = array('%type_name' => $type->label());
     return array("view any unpublished {$type_id} content" => array('title' => $this->t('%type_name: View any unpublished content', $type_params)));
 }
开发者ID:dakala,项目名称:view_unpublished,代码行数:15,代码来源:ViewUnpublishedPermissions.php


注:本文中的Drupal\node\Entity\NodeType::id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。