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


PHP EntityTypeInterface::hasKey方法代码示例

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


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

示例1: testToUrlLinkTemplateAddForm

 /**
  * Tests the toUrl() method with the 'revision' link template.
  *
  * @param bool $has_bundle_key
  *   Whether or not the mock entity type should have a bundle key.
  * @param string|null $bundle_entity_type
  *   The ID of the bundle entity type of the mock entity type, or NULL if the
  *   mock entity type should not have a bundle entity type.
  * @param string $bundle_key
  *   The bundle key of the mock entity type or FALSE if the entity type should
  *   not have a bundle key.
  * @param array $expected_route_parameters
  *   The expected route parameters of the generated URL.
  *
  * @dataProvider providerTestToUrlLinkTemplateAddForm
  *
  * @covers ::toUrl
  * @covers ::linkTemplates
  * @covers ::urlRouteParameters
  */
 public function testToUrlLinkTemplateAddForm($has_bundle_key, $bundle_entity_type, $bundle_key, $expected_route_parameters)
 {
     $values = ['id' => $this->entityId, 'langcode' => $this->langcode];
     $entity = $this->getEntity(Entity::class, $values);
     $this->entityType->hasKey('bundle')->willReturn($has_bundle_key);
     $this->entityType->getBundleEntityType()->willReturn($bundle_entity_type);
     $this->entityType->getKey('bundle')->willReturn($bundle_key);
     $link_template = 'add-form';
     $this->registerLinkTemplate($link_template);
     /** @var \Drupal\Core\Url $url */
     $url = $entity->toUrl($link_template);
     $this->assertUrl('entity.test_entity.add_form', $expected_route_parameters, $entity, FALSE, $url);
 }
开发者ID:DrupalCamp-NYC,项目名称:dcnyc16,代码行数:33,代码来源:EntityUrlTest.php

示例2: getReferenceableEntities

  /**
   * Gets the entities that can be filtered by.
   *
   * @return \Drupal\Core\Entity\EntityInterface[]
   */
  protected function getReferenceableEntities() {
    if ($this->referenceableEntities !== NULL) {
      return $this->referenceableEntities;
    }
    $target_ids = NULL;

    // Filter by bundle if if the plugin was configured to do so.
    $target_bundles = array_filter($this->options['verf_target_bundles']);
    if ($this->targetEntityType->hasKey('bundle') && $target_bundles) {
      $query = $this->targetEntityStorage->getQuery();
      $query->condition($this->targetEntityType->getKey('bundle'), $target_bundles, 'IN');
      $target_ids = $query->execute();
    }

    $this->referenceableEntities = $this->targetEntityStorage->loadMultiple($target_ids);
    return $this->referenceableEntities;
  }
开发者ID:eloiv,项目名称:botafoc.cat,代码行数:22,代码来源:EntityReference.php

示例3: buildFilters

 /**
  * Builds the form structure for selecting the view's filters.
  *
  * By default, this adds "of type" and "tagged with" filters (when they are
  * available).
  */
 protected function buildFilters(&$form, FormStateInterface $form_state)
 {
     module_load_include('inc', 'views_ui', 'admin');
     $bundles = entity_get_bundles($this->entityTypeId);
     // If the current base table support bundles and has more than one (like user).
     if (!empty($bundles) && $this->entityType && $this->entityType->hasKey('bundle')) {
         // Get all bundles and their human readable names.
         $options = array('all' => $this->t('All'));
         foreach ($bundles as $type => $bundle) {
             $options[$type] = $bundle['label'];
         }
         $form['displays']['show']['type'] = array('#type' => 'select', '#title' => $this->t('of type'), '#options' => $options);
         $selected_bundle = static::getSelected($form_state, array('show', 'type'), 'all', $form['displays']['show']['type']);
         $form['displays']['show']['type']['#default_value'] = $selected_bundle;
         // Changing this dropdown updates the entire content of $form['displays']
         // via AJAX, since each bundle might have entirely different fields
         // attached to it, etc.
         views_ui_add_ajax_trigger($form['displays']['show'], 'type', array('displays'));
     }
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:26,代码来源:WizardPluginBase.php

示例4: getEntityBundleOptions

 /**
  * Builds a list of entity type bundle options.
  *
  * Configuration entity types without a view builder are filtered out while
  * all other entity types are kept.
  *
  * @return array
  *   An array of bundle labels, keyed by bundle name.
  */
 protected function getEntityBundleOptions(EntityTypeInterface $entity_type)
 {
     $bundle_options = array();
     // If the entity has bundles, allow option to restrict to bundle(s).
     if ($entity_type->hasKey('bundle')) {
         foreach ($this->entityTypeBundleInfo->getBundleInfo($entity_type->id()) as $bundle_id => $bundle_info) {
             $bundle_options[$bundle_id] = $bundle_info['label'];
         }
         natsort($bundle_options);
     }
     return $bundle_options;
 }
开发者ID:nB-MDSO,项目名称:mdso-d8blog,代码行数:21,代码来源:Entity.php

示例5: baseFieldDefinitions

 /**
  * {@inheritdoc}
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields = [];
     if ($entity_type->hasKey('id')) {
         $fields[$entity_type->getKey('id')] = BaseFieldDefinition::create('integer')->setLabel(new TranslatableMarkup('ID'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE);
     }
     if ($entity_type->hasKey('uuid')) {
         $fields[$entity_type->getKey('uuid')] = BaseFieldDefinition::create('uuid')->setLabel(new TranslatableMarkup('UUID'))->setReadOnly(TRUE);
     }
     if ($entity_type->hasKey('revision')) {
         $fields[$entity_type->getKey('revision')] = BaseFieldDefinition::create('integer')->setLabel(new TranslatableMarkup('Revision ID'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE);
     }
     if ($entity_type->hasKey('langcode')) {
         $fields[$entity_type->getKey('langcode')] = BaseFieldDefinition::create('language')->setLabel(new TranslatableMarkup('Language'))->setDisplayOptions('view', ['type' => 'hidden'])->setDisplayOptions('form', ['type' => 'language_select', 'weight' => 2]);
         if ($entity_type->isRevisionable()) {
             $fields[$entity_type->getKey('langcode')]->setRevisionable(TRUE);
         }
         if ($entity_type->isTranslatable()) {
             $fields[$entity_type->getKey('langcode')]->setTranslatable(TRUE);
         }
     }
     if ($entity_type->hasKey('bundle')) {
         if ($bundle_entity_type_id = $entity_type->getBundleEntityType()) {
             $fields[$entity_type->getKey('bundle')] = BaseFieldDefinition::create('entity_reference')->setLabel($entity_type->getBundleLabel())->setSetting('target_type', $bundle_entity_type_id)->setRequired(TRUE)->setReadOnly(TRUE);
         } else {
             $fields[$entity_type->getKey('bundle')] = BaseFieldDefinition::create('string')->setLabel($entity_type->getBundleLabel())->setRequired(TRUE)->setReadOnly(TRUE);
         }
     }
     return $fields;
 }
开发者ID:318io,项目名称:318-io,代码行数:33,代码来源:ContentEntityBase.php


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