Commit 5875259f authored by Kingdutch's avatar Kingdutch

Issue #2922548 by Kingdutch, Skin: Fix bundle selection on configuration page

parent 1309762f
......@@ -170,7 +170,7 @@ class FieldManager {
*/
public function isAttached($entity_type_id, $bundle, $field_name) {
$field = FieldConfig::loadByName($entity_type_id, $bundle, $field_name);
return is_null($field);
return !is_null($field);
}
}
......@@ -70,7 +70,7 @@ class ConfigForm extends FormBase {
'#title' => $this->t('@label', ['@label' => $entity_label]),
'#options' => $supported_bundles[$entity_type],
'#required' => FALSE,
'#default_value' => $enabled_bundles[$entity_type],
'#default_value' => array_keys($enabled_bundles[$entity_type]),
];
}
......@@ -106,9 +106,9 @@ class ConfigForm extends FormBase {
// TODO: Try and simplify the below logic.
foreach ($entity_types as $entity_type_id => $entity_type_label) {
// Get the available bundles Yoast SEO supports.
$bundles = $this->seoManager->getEntityBundles($entity_type_id);
$bundles = $this->seoManager->getEntityBundles([$entity_type_id])[$entity_type_id];
// Get the bundles Yoast SEO has been enabled for.
$enabled_bundles = $this->seoManager->getEnabledBundles($entity_type_id);
$enabled_bundles = array_keys($this->seoManager->getEnabledBundles([$entity_type_id])[$entity_type_id]);
// Foreach available bundles.
foreach ($bundles as $bundle_id => $bundle_label) {
......
......@@ -107,9 +107,10 @@ class SeoManager {
*/
public function getEnabledBundles(array $entity_types = NULL) {
$entities = $this->getEntityBundles($entity_types);
$field_name = $this->fieldManager->getFieldDefinitions()[0];
// TODO: Clean up the next line.
$field_name = array_keys($this->fieldManager->getFieldDefinitions())[0];
foreach ($entities as $entity_type => $bundles) {
foreach ($entities as $entity_type => &$bundles) {
foreach ($bundles as $bundle_id => $bundle_label) {
if (!$this->fieldManager->isAttached($entity_type, $bundle_id, $field_name)) {
unset($bundles[$bundle_id]);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment