コード例 #1
0
ファイル: EntityManagerTest.php プロジェクト: aWEBoLabs/taxi
 /**
  * Tests the clearCachedDefinitions() method.
  *
  * @covers ::clearCachedDefinitions
  */
 public function testClearCachedDefinitions()
 {
     $this->entityTypeManager->clearCachedDefinitions()->shouldBeCalled();
     $this->entityTypeRepository->clearCachedDefinitions()->shouldBeCalled();
     $this->entityTypeBundleInfo->clearCachedBundles()->shouldBeCalled();
     $this->entityFieldManager->clearCachedFieldDefinitions()->shouldBeCalled();
     $this->entityManager->clearCachedDefinitions();
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, PageInterface $page = NULL, $name = '')
 {
     $this->page = $page;
     $this->staticContext = $this->page->getStaticContext($name);
     // Allow the condition to add to the form.
     $form['label'] = ['#type' => 'textfield', '#title' => $this->t('Label'), '#default_value' => isset($this->staticContext['label']) ? $this->staticContext['label'] : '', '#required' => TRUE];
     $form['machine_name'] = ['#type' => 'machine_name', '#maxlength' => 64, '#required' => TRUE, '#machine_name' => ['exists' => [$this, 'contextExists'], 'source' => ['label']], '#default_value' => $name];
     $form['entity_type'] = ['#type' => 'select', '#title' => $this->t('Entity type'), '#options' => $this->entityTypeRepository->getEntityTypeLabels(TRUE), '#limit_validation_errors' => array(array('entity_type')), '#submit' => ['::rebuildSubmit'], '#executes_submit_callback' => TRUE, '#ajax' => array('callback' => '::updateEntityType', 'wrapper' => 'add-static-context-wrapper', 'method' => 'replace')];
     $entity = NULL;
     if ($form_state->hasValue('entity_type')) {
         $entity_type = $form_state->getValue('entity_type');
         if ($this->staticContext['value']) {
             $entity = $this->entityRepository->loadEntityByUuid($entity_type, $this->staticContext['value']);
         }
     } elseif (!empty($this->staticContext['type'])) {
         list(, $entity_type) = explode(':', $this->staticContext['type']);
         $entity = $this->entityRepository->loadEntityByUuid($entity_type, $this->staticContext['value']);
     } elseif ($this->entityTypeManager->hasDefinition('node')) {
         $entity_type = 'node';
     } else {
         $entity_type = 'user';
     }
     $form['entity_type']['#default_value'] = $entity_type;
     $form['selection'] = ['#type' => 'entity_autocomplete', '#prefix' => '<div id="add-static-context-wrapper">', '#suffix' => '</div>', '#required' => TRUE, '#target_type' => $entity_type, '#default_value' => $entity, '#title' => $this->t('Select entity')];
     $form['actions'] = ['#type' => 'actions'];
     $form['actions']['submit'] = ['#type' => 'submit', '#value' => $this->submitButtonText(), '#button_type' => 'primary'];
     return $form;
 }
コード例 #3
0
ファイル: Entity.php プロジェクト: nB-MDSO/mdso-d8blog
 /**
  * Builds a list of entity type options.
  *
  * Configuration entity types without a view builder are filtered out while
  * all other entity types are kept.
  *
  * @return array
  *   An array of entity type labels, keyed by entity type name.
  */
 protected function getEntityTypeOptions()
 {
     $options = $this->entityTypeRepository->getEntityTypeLabels(TRUE);
     foreach ($options as $group => $group_types) {
         foreach (array_keys($group_types) as $entity_type_id) {
             // Filter out entity types that do not have a view builder class.
             if (!$this->entityTypeManager->getDefinition($entity_type_id)->hasViewBuilderClass()) {
                 unset($options[$group][$entity_type_id]);
             }
             // Filter out entity types that will not have any Entity Embed Display
             // plugins.
             if (!$this->displayPluginManager->getDefinitionOptionsForEntityType($entity_type_id)) {
                 unset($options[$group][$entity_type_id]);
             }
         }
     }
     return $options;
 }
コード例 #4
0
 /**
  * Builds an array of options for the parameter type.
  *
  * @return array[]
  *   A multidimensional array. The top level is keyed by group ('Content',
  *   'Configuration', 'Typed Data'). Those values are an array of type labels,
  *   keyed by the machine name.
  */
 protected function buildParameterTypeOptions()
 {
     $options = [static::NO_CONTEXT_KEY => $this->t('No context selected')];
     // Make a grouped, sorted list of entity type options. Key the inner array
     // to use the typed data format of 'entity:$entity_type_id'.
     foreach ($this->entityTypeRepository->getEntityTypeLabels(TRUE) as $group_label => $grouped_options) {
         foreach ($grouped_options as $key => $label) {
             $options[$group_label]['entity:' . $key] = $label;
         }
     }
     $primitives_label = (string) $this->t('Primitives');
     foreach ($this->typedDataManager->getDefinitions() as $key => $definition) {
         if (is_subclass_of($definition['class'], PrimitiveInterface::class)) {
             $options[$primitives_label][$key] = $definition['label'];
         }
     }
     asort($options[$primitives_label], SORT_NATURAL);
     return $options;
 }