protected function FeaturesExportForm::buildPackageDetail in Features 8.4
Same name and namespace in other branches
- 8.3 modules/features_ui/src/Form/FeaturesExportForm.php \Drupal\features_ui\Form\FeaturesExportForm::buildPackageDetail()
Builds the details of a package.
Parameters
\Drupal\features\Package $package: The package.
\Drupal\features\FeaturesBundleInterface $bundle: The current bundle.
Return value
array A render array of a form element.
1 call to FeaturesExportForm::buildPackageDetail()
- FeaturesExportForm::buildListing in modules/
features_ui/ src/ Form/ FeaturesExportForm.php - Builds the portion of the form showing a listing of features.
File
- modules/
features_ui/ src/ Form/ FeaturesExportForm.php, line 296
Class
- FeaturesExportForm
- Defines the configuration export form.
Namespace
Drupal\features_ui\FormCode
protected function buildPackageDetail(Package $package, FeaturesBundleInterface $bundle) {
$config_collection = $this->featuresManager
->getConfigCollection();
$url = Url::fromRoute('features.edit', [
'featurename' => $package
->getMachineName(),
]);
$element['name'] = [
'data' => \Drupal::service('link_generator')
->generate($package
->getName(), $url),
'class' => [
'feature-name',
],
];
$machine_name = $package
->getMachineName();
// Except for the 'unpackaged' pseudo-package, display the full name, since
// that's what will be generated.
if ($machine_name !== 'unpackaged') {
$machine_name = $bundle
->getFullName($machine_name);
}
$element['machine_name'] = $machine_name;
$element['status'] = [
'data' => $this->featuresManager
->statusLabel($package
->getStatus()),
'class' => [
'column-nowrap',
],
];
// Use 'data' instead of plain string value so a blank version doesn't
// remove column from table.
$element['version'] = [
'data' => Html::escape($package
->getVersion()),
'class' => [
'column-nowrap',
],
];
$overrides = $this->featuresManager
->detectOverrides($package);
$new_config = $this->featuresManager
->detectNew($package);
$conflicts = [];
$missing = [];
$moved = [];
if ($package
->getStatus() == FeaturesManagerInterface::STATUS_NO_EXPORT) {
$overrides = [];
$new_config = [];
}
// Bundle package configuration by type.
$package_config = [];
foreach ($package
->getConfig() as $item_name) {
if (isset($config_collection[$item_name])) {
$item = $config_collection[$item_name];
$package_config[$item
->getType()][] = [
'name' => Html::escape($item_name),
'label' => Html::escape($item
->getLabel()),
'class' => in_array($item_name, $overrides) ? 'features-override' : (in_array($item_name, $new_config) ? 'features-detected' : ''),
];
}
}
// Conflict config from other modules.
foreach ($package
->getConfigOrig() as $item_name) {
if (!isset($config_collection[$item_name])) {
$missing[] = $item_name;
$package_config['missing'][] = [
'name' => Html::escape($item_name),
'label' => Html::escape($item_name),
'class' => 'features-missing',
];
}
elseif (!in_array($item_name, $package
->getConfig())) {
$item = $config_collection[$item_name];
if (empty($item
->getProvider())) {
$conflicts[] = $item_name;
$package_name = !empty($item
->getPackage()) ? $item
->getPackage() : $this
->t('PACKAGE NOT ASSIGNED');
$package_config[$item
->getType()][] = [
'name' => Html::escape($package_name),
'label' => Html::escape($item
->getLabel()),
'class' => 'features-conflict',
];
}
else {
$moved[] = $item_name;
$package_name = !empty($item
->getPackage()) ? $item
->getPackage() : $this
->t('PACKAGE NOT ASSIGNED');
$package_config[$item
->getType()][] = [
'name' => $this
->t('Moved to @package', [
'@package' => $package_name,
]),
'label' => Html::escape($item
->getLabel()),
'class' => 'features-moved',
];
}
}
}
// Add dependencies.
$package_config['dependencies'] = [];
foreach ($package
->getDependencies() as $dependency) {
$package_config['dependencies'][] = [
'name' => $dependency,
'label' => $this->moduleHandler
->moduleExists($dependency) ? $this->moduleHandler
->getName($dependency) : $dependency,
'class' => '',
];
}
$class = '';
$state_links = [];
if (!empty($conflicts)) {
$state_links[] = [
'#type' => 'link',
'#title' => $this
->t('Conflicts'),
'#url' => Url::fromRoute('features.edit', [
'featurename' => $package
->getMachineName(),
]),
'#attributes' => [
'class' => [
'features-conflict',
],
],
];
}
if (!empty($overrides)) {
$state_links[] = [
'#type' => 'link',
'#title' => $this->featuresManager
->stateLabel(FeaturesManagerInterface::STATE_OVERRIDDEN),
'#url' => Url::fromRoute('features.diff', [
'featurename' => $package
->getMachineName(),
]),
'#attributes' => [
'class' => [
'features-override',
],
],
];
}
if (!empty($new_config)) {
$state_links[] = [
'#type' => 'link',
'#title' => $this
->t('New detected'),
'#url' => Url::fromRoute('features.diff', [
'featurename' => $package
->getMachineName(),
]),
'#attributes' => [
'class' => [
'features-detected',
],
],
];
}
if (!empty($missing) && $package
->getStatus() == FeaturesManagerInterface::STATUS_INSTALLED) {
$state_links[] = [
'#type' => 'link',
'#title' => $this
->t('Missing'),
'#url' => Url::fromRoute('features.edit', [
'featurename' => $package
->getMachineName(),
]),
'#attributes' => [
'class' => [
'features-missing',
],
],
];
}
if (!empty($moved)) {
$state_links[] = [
'#type' => 'link',
'#title' => $this
->t('Moved'),
'#url' => Url::fromRoute('features.edit', [
'featurename' => $package
->getMachineName(),
]),
'#attributes' => [
'class' => [
'features-moved',
],
],
];
}
if (!empty($state_links)) {
$element['state'] = [
'data' => $state_links,
'class' => [
'column-nowrap',
],
];
}
else {
$element['state'] = '';
}
$config_types = $this->featuresManager
->listConfigTypes();
// Add dependencies.
$config_types['dependencies'] = $this
->t('Dependencies');
$config_types['missing'] = $this
->t('Missing');
uasort($config_types, 'strnatcasecmp');
$rows = [];
// Use sorted array for order.
foreach ($config_types as $type => $label) {
// For each component type, offer alternating rows.
$row = [];
if (isset($package_config[$type])) {
$row[] = [
'data' => [
'#type' => 'html_tag',
'#tag' => 'span',
'#value' => Html::escape($label),
'#attributes' => [
'title' => Html::escape($type),
'class' => 'features-item-label',
],
],
];
$row[] = [
'data' => [
'#theme' => 'features_items',
'#items' => $package_config[$type],
'#value' => Html::escape($label),
'#title' => Html::escape($type),
],
'class' => 'item',
];
$rows[] = $row;
}
}
$element['table'] = [
'#type' => 'table',
'#rows' => $rows,
];
$details = [];
$details['description'] = [
'#markup' => Xss::filterAdmin($package
->getDescription()),
];
$details['table'] = [
'#type' => 'details',
'#title' => $this
->t('Included configuration'),
'#description' => [
'data' => $element['table'],
],
];
$element['details'] = [
'class' => [
'description',
'expand',
],
'data' => $details,
];
return $element;
}