コード例 #1
0
 /**
  * Returns entity (form) displays for the current entity display type.
  *
  * @return \Drupal\Core\Entity\Display\EntityDisplayInterface[]
  *   An array holding entity displays or entity form displays.
  */
 protected function getDisplays()
 {
     $load_ids = array();
     $display_entity_type = $this->entity->getEntityTypeId();
     $entity_type = $this->entityManager->getDefinition($display_entity_type);
     $config_prefix = $entity_type->getConfigPrefix();
     $ids = $this->configFactory()->listAll($config_prefix . '.' . $this->entity->getTargetEntityTypeId() . '.' . $this->entity->getTargetBundle() . '.');
     foreach ($ids as $id) {
         $config_id = str_replace($config_prefix . '.', '', $id);
         list(, , $display_mode) = explode('.', $config_id);
         if ($display_mode != 'default') {
             $load_ids[] = $config_id;
         }
     }
     return $this->entityManager->getStorage($display_entity_type)->loadMultiple($load_ids);
 }
コード例 #2
0
ファイル: EntityDisplayTest.php プロジェクト: isramv/camp-gdl
 /**
  * Provides a helper for dependency assertions.
  *
  * @param bool $assertion
  *   Assertion: positive or negative.
  * @param string $type
  *   The dependency type: 'config', 'content', 'module' or 'theme'.
  * @param string $key
  *   The string to be checked.
  * @param \Drupal\Core\Entity\Display\EntityDisplayInterface $display
  *   The entity display object to get dependencies from.
  *
  * @return bool
  *   TRUE if the assertion succeeded, FALSE otherwise.
  */
 protected function assertDependencyHelper($assertion, $type, $key, EntityDisplayInterface $display)
 {
     $all_dependencies = $display->getDependencies();
     $dependencies = !empty($all_dependencies[$type]) ? $all_dependencies[$type] : [];
     $context = $display instanceof EntityViewDisplayInterface ? 'View' : 'Form';
     $value = $assertion ? in_array($key, $dependencies) : !in_array($key, $dependencies);
     $args = ['@context' => $context, '@id' => $display->id(), '@type' => $type, '@key' => $key];
     $message = $assertion ? new FormattableMarkup("@context display '@id' depends on @type '@key'.", $args) : new FormattableMarkup("@context display '@id' do not depend on @type '@key'.", $args);
     return $this->assert($value, $message);
 }
コード例 #3
0
 /**
  * Builds the table row structure for a single extra field.
  *
  * @param string $field_id
  *   The field ID.
  * @param array $extra_field
  *   The pseudo-field element.
  * @param \Drupal\Core\Entity\Display\EntityDisplayInterface $entity_display
  *   The entity display.
  *
  * @return array
  *   A table row array.
  */
 protected function buildExtraFieldRow($field_id, $extra_field, EntityDisplayInterface $entity_display)
 {
     $display_options = $entity_display->getComponent($field_id);
     $regions = array_keys($this->getRegions());
     $extra_field_row = array('#attributes' => array('class' => array('draggable', 'tabledrag-leaf')), '#row_type' => 'extra_field', '#region_callback' => array($this, 'getRowRegion'), '#js_settings' => array('rowHandler' => 'field'), 'human_name' => array('#markup' => $extra_field['label']), 'weight' => array('#type' => 'textfield', '#title' => $this->t('Weight for @title', array('@title' => $extra_field['label'])), '#title_display' => 'invisible', '#default_value' => $display_options ? $display_options['weight'] : 0, '#size' => 3, '#attributes' => array('class' => array('field-weight'))), 'parent_wrapper' => array('parent' => array('#type' => 'select', '#title' => $this->t('Parents for @title', array('@title' => $extra_field['label'])), '#title_display' => 'invisible', '#options' => array_combine($regions, $regions), '#empty_value' => '', '#attributes' => array('class' => array('field-parent')), '#parents' => array('fields', $field_id, 'parent')), 'hidden_name' => array('#type' => 'hidden', '#default_value' => $field_id, '#attributes' => array('class' => array('field-name')))), 'plugin' => array('type' => array('#type' => 'select', '#title' => $this->t('Visibility for @title', array('@title' => $extra_field['label'])), '#title_display' => 'invisible', '#options' => $this->getExtraFieldVisibilityOptions(), '#default_value' => $display_options ? 'visible' : 'hidden', '#parents' => array('fields', $field_id, 'type'), '#attributes' => array('class' => array('field-plugin-type')))), 'settings_summary' => array(), 'settings_edit' => array());
     return $extra_field_row;
 }