I am trying my hand at writing modules and keep getting confused about factories and controllers and helpers and when to use them, and when to not. In the documentation, one of the things it suggests is to look at existing modules to see how they are put together, and while that helps with some things, it adds to the confusion with others.
What I am currently trying to do is make a configurable module to add a
$colorScheme => [
'name' => 'o:color_1',
'type' => Element\Color::class,
'options' => [
'element_group' => 'color-scheme', // @translate
'label' => 'Color #1', // @translate
],
'attributes' => [
'id' => $color1,
],
'variations' => [
[
'name' => 'light', // @translate
'type' => Element\Color::class,
'options' => [
'label' => 'Color #1 (Light)', // @translate
'value' => '<?php echo $this->ShadeColor($color1, 10); ?>',
],
'attributes' => [
'id' => $color1_light,
],
],
[
'name' => 'dark', // @translate
'type' => Element\Color::class,
'options' => [
'label' => 'Color #1 (Dark)', // @translate
'value' => '<?php echo $this->ShadeColor($color1, -10); ?>',
],
'attributes' => [
'id' => $color1_dark,
],
],
],
]);
// color2, color3...
And would like to add swatches onto the Welcome page. Possibly something like this:
<div class="colorSwatches">
<svg height="600" style="box-shadow: 5px 5px 5px #00000075;" width="800">
<rect fill="$color1" height="600" width="140" x="0" y="0"></rect>
<rect fill="$color2" height="600" width="140" x="140" y="0"></rect>
<rect fill="$color3" height="600" width="140" x="280" y="0"></rect>
<rect fill="$color4" height="600" width="140" x="420" y="0"></rect>
<rect fill="$color5" height="600" width="140" x="560" y="0"></rect>
<rect fill="$color1_light" height="550" width="10" x="100" y="25"></rect>
<rect fill="$color2_light" height="550" width="10" x="240" y="25"></rect>
<rect fill="$color3_light" height="550" width="10" x="380" y="25"></rect>
<rect fill="$color4_light" height="550" width="10" x="520" y="25"></rect>
<rect fill="$color5_light" height="550" width="10" x="660" y="25"></rect>
<rect fill="$color1_dark" height="550" width="10" x="110" y="25"></rect>
<rect fill="$color2_dark" height="550" width="10" x="250" y="25"></rect>
<rect fill="$color3_dark" height="550" width="10" x="390" y="25"></rect>
<rect fill="$color4_dark" height="550" width="10" x="530" y="25"></rect>
<rect fill="$color5_dark" height="550" width="10" x="670" y="25"></rect>
<rect fill="$white" height="100" width="130" x="700" y="0"></rect>
<rect fill="$grey1" height="100" width="130" x="700" y="100"></rect>
<rect fill="$grey2" height="100" width="130" x="700" y="200"></rect>
<rect fill="$grey3" height="100" width="130" x="700" y="300"></rect>
<rect fill="$grey4" height="100" width="130" x="700" y="400"></rect>
<rect fill="$black" height="100" width="130" x="700" y="500"></rect>
<rect fill="$white" height="25" width="750" x="50" y="65"></rect>
<rect fill="$grey1" height="25" width="750" x="50" y="165"></rect>
<rect fill="$grey2" height="25" width="750" x="50" y="265"></rect>
<rect fill="$grey3" height="25" width="750" x="50" y="365"></rect>
<rect fill="$grey4" height="25" width="750" x="50" y="465"></rect>
<rect fill="$black" height="25" width="750" x="50" y="565"></rect>
</svg>
</div>
(prints similar to this:)
(Although I’m also thinking about making draggable swatches, so in that case would probably just do 100px squares, but that’s not an important part of the question. Another possibility is to make this a “Sample Block” block template that is separate from the original Welcome Page.)
So far (at least this iteration), I have found where the Welcome page is set up with the omeka-s/application/src/Api/Adapter/SiteAdapter.php, and am confident that I can insert the above svg just fine. However, where I run into confusion is how to set it up to be configurable and make sure that it’s overriding the themeSettings. Should I concentrate on adding it to the themeSettings instead of the siteSettings? But then wouldn’t it be theme-specific since many of them set up their colors and such different? Should I just make this a theme?
If adding it to the siteSettings is the way to go, I have found the omeka-s/application/src/Form/SiteSettingsForm.php , but then I have questions like where do I put the helper, ShadeColor
? It was originally part of the Freedom Theme, so would I mimic that (/helper/ShadeColor.php)?
And is this the right way to get the siteSettings that were defined in the siteSettingsForm and put them into the siteAdapter’s page content?
protected function getFirstPageContent()
{
$colors = $this->siteSettings['element_group']['color-scheme'] ?? [];
public function getColors(['color-scheme']) {
foreach ($colors as $color) {
'id' => 'id';
'value' => 'value';
'variations' => $variations;
foreach ($variations as $variation) {
'id' => 'id';
'value' => 'value';
};
$variationName = (if (in_array($this, $variations)) {echo "_" . $variations['name'];}) ?? '';
$colorId = $color . ['id'] . $variationName;
};
$translator = $this->getServiceLocator()->get('MvcTranslator');
return $translator->translate(<<<EOT
<div class="colorSwatches">...(you saw this above...)
Please forgive me if the answer seems super easy.