silverstripe / silverstripe-elemental

Create pages in Silverstripe CMS using content blocks
http://dna.co.nz
BSD 3-Clause "New" or "Revised" License
110 stars 116 forks source link

Using >1 ElementalArea confuses content authors #758

Open phptek opened 5 years ago

phptek commented 5 years ago

For projects that have migrated to Elemental from other Blocks modules, CMS authors are used to seeing at-a-glance, which "Area" within a page, their block will be added to.

OOTB, I see no easy way to prepend a HeadingField or something similar before each ElementalArea - in fact, AFAICT, the standard Silverstripe forms API doesn't work as expected: If I try to use $fields->insertBefore() in an additional DataExtension subclass, the headings are added, but in a completely different spot in the CMS' UI.

I had to resort to the folowing hackery to make it work (Unless of course I am missing something)

1). Subclass ElementalPageExtension (Which itself subclasses ElementalAreasExtension) 2). Overlload updateCMSFields() and lightly modify as per the following:

$label = sprintf('%s Blocks', ucwords(FormField::name_to_label(str_replace('ID', '', $key))));
$heading = NoticeMessage::create($label, "Area_{$key}");

if ($this->owner instanceof SiteTree && $fields->findOrMakeTab('Root.Main')->fieldByName('Metadata')) {
    $fields->addFieldsToTab('Root.Main', [$heading, $editor], 'Metadata');
} else {
    $fields->addFieldsToTab('Root.Main', [$heading, $editor]);
}

This shouldn't be too hard to configure as an opt-in using the Config system - that is as I said, unless I'm missing something.

brynwhyman commented 5 years ago

Do you mean like this?

image

You can see the above implementation in the Silverstripe demo

Codebase is here: silverstripe/bambusa-installer

phptek commented 4 years ago

Yeah, like that but make it OOTB functionality, part of the Elemental / SIlverstripe forms API.

Cheers!

mfendeksilverstripe commented 4 years ago

I recommend to avoid having multiple elemental areas on a page. See https://github.com/dnadesign/silverstripe-elemental/issues/759 for more details.

michalkleiner commented 4 years ago

I'd support making the heading part of the area, being optional.

tractorcow commented 4 years ago

My solution is to just use ElementalAreasExtension directly, and not the pages specific one, and then add the block headers manually.

same as the demo solution actually.

$fields->insertBefore('HeaderArea', HeaderField::create('HeaderAreaTitle', 'Page heading blocks'));
$fields->insertBefore('BodyArea', HeaderField::create('BodyAreaTitle', 'Main content blocks'));