/** * {@inheritdoc} */ public function getDerivativeDefinitions(array $base_plugin_definition) { foreach ($this->entityManager->getDefinitions() as $entity_type => $entity_info) { // Only show content entities for now. if (!$entity_info->isSubclassOf('Drupal\\Core\\Config\\Entity\\ConfigEntityInterface')) { $this->derivatives[$entity_type] = $base_plugin_definition; $this->derivatives[$entity_type]['title'] = $entity_info->getLabel(); $this->derivatives[$entity_type]['entity type'] = $entity_type; } } $this->sortDerivatives(); return $this->derivatives; }
protected function getConfigTypes() { $this->entityManager = $this->getDrupalService('entity_type.manager'); foreach ($this->entityManager->getDefinitions() as $entity_type => $definition) { if ($definition->isSubclassOf('Drupal\\Core\\Config\\Entity\\ConfigEntityInterface')) { $this->definitions[$entity_type] = $definition; } } $entity_types = array_map(function ($definition) { return $definition->getLabel(); }, $this->definitions); uasort($entity_types, 'strnatcasecmp'); $config_types = array('system.simple' => $this->trans('commands.config.export.single.options.simple-configuration')) + $entity_types; return $config_types; }
/** * {@inheritdoc} */ protected function writeCache() { $data = array(); foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) { $reflection = new \ReflectionClass($entity_type->getClass()); // We are only interested in importing content entities. if ($reflection->implementsInterface('\\Drupal\\Core\\Config\\Entity\\ConfigEntityInterface') || !$reflection->hasMethod('baseFieldDefinitions')) { continue; } foreach (array_keys($this->entityManager->getBundleInfo($entity_type_id)) as $bundle) { foreach ($this->entityManager->getFieldDefinitions($entity_type_id, $bundle) as $field_name => $field_details) { $relation_uri = $this->getRelationUri($entity_type_id, $bundle, $field_name); $data[$relation_uri] = array('entity_type' => $entity_type_id, 'bundle' => $bundle, 'field_name' => $field_name); } } } // These URIs only change when field info changes, so cache it permanently // and only clear it when field_info is cleared. $this->cache->set('rest:links:relations', $data, CacheBackendInterface::CACHE_PERMANENT, array('field_info')); }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, $field_key = '') { // Initialize field. $field = array(); // Fetch field if it already exists. if (!empty($field_key)) { $field = $this->config('ds.field.' . $field_key)->get(); } // Save the field for future reuse. $this->field = $field; $form['name'] = array( '#title' => t('Label'), '#type' => 'textfield', '#default_value' => isset($field['label']) ? $field['label'] : '', '#description' => t('The human-readable label of the field.'), '#maxlength' => 128, '#required' => TRUE, '#size' => 30, ); $form['id'] = array( '#type' => 'machine_name', '#default_value' => isset($field['id']) ? $field['id'] : '', '#maxlength' => 32, '#description' => t('The machine-readable name of this field. This name must contain only lowercase letters and underscores. This name must be unique.'), '#disabled' => !empty($field['id']), '#machine_name' => array( 'exists' => array($this, 'uniqueFieldName'), 'source' => array('name'), ), ); $entity_options = array(); $entities = $this->entityManager->getDefinitions(); foreach ($entities as $entity_type => $entity_info) { if ($entity_info->get('field_ui_base_route') || $entity_type == 'ds_views') { $entity_options[$entity_type] = Unicode::ucfirst(str_replace('_', ' ', $entity_type)); } } $form['entities'] = array( '#title' => t('Entities'), '#description' => t('Select the entities for which this field will be made available.'), '#type' => 'checkboxes', '#required' => TRUE, '#options' => $entity_options, '#default_value' => isset($field['entities']) ? $field['entities'] : array(), ); $form['ui_limit'] = array( '#title' => t('Limit field'), '#description' => t('Limit this field on field UI per bundles and/or view modes. The values are in the form of $bundle|$view_mode, where $view_mode may be either a view mode set to use custom settings, or \'default\'. You may use * to select all, e.g article|*, *|full or *|*. Enter one value per line.'), '#type' => 'textarea', '#default_value' => isset($field['ui_limit']) ? $field['ui_limit'] : '', ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Save'), '#weight' => 100, ); return $form; }