當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。