Honestly, in all my time with C5, I've never felt the need to do this. But my last post gave me a pretty good reason.
We used Global Areas to create "sectionwide" areas. It works great, but there's one small annoyance... the add text says "Add To Sidewide Product 123 Sidebar". Well, from an editors perspective, it's not "sitewide", it's "productwide". Also, does an editor really need/want to see that cID number?
Fortunately, areas can have attributes, which makes changing the "Add To..." text a pretty quick and safe job.
Step 1: Override Core Area Footer
We need to modify C5 core code. To accomplish this in a "safe" way, we'll take advantage of C5's override system. Copy /concrete/elements/block_area_footer.php
to /elements/block_area_footer.php
. C5 will now use this copied file instead of the core file.
Open /elements/block_area_footer.php
and notice this code at the bottom:
<?php if ($a->isGlobalArea()) { ?> <div id="a<?php echo $a->getAreaID()?>controls" class="ccm-add-block"><?php echo t('Add To Sitewide %s', $arHandle)?></div> <?php } else { ?> <div id="a<?php echo $a->getAreaID()?>controls" class="ccm-add-block"><?php echo t('Add To %s', $arHandle)?></div> <?php } ?>
Replace it with:
<?php // default add text if ($a->isGlobalArea()) { $addText = t('Add To Sitewide %s', $arHandle); } else { $addText = t('Add To %s', $arHandle); } // optional custom add text if ($a->getAttribute('add_text')) { $addText = $a->getAttribute('add_text'); } ?> <div id="a<?php echo $a->getAreaID()?>controls" class="ccm-add-block"><?php echo $addText; ?></div>
This keeps the default "Add To..." text, but now allows us to set custom text via an "add_text" area attribute.
Step 2: Set Attribute in Area Definition
Now with a simple line of code, we have custom text.
Before:
<?php $a = new Area('Sidebar'); $a->display($c); ?>
After:
<?php $a = new Area('Sidebar'); $a->setAttribute('add_text', 'This is custom text'); $a->display($c); ?>

That example was a standard "Sidebar" area. Updated code for last post would be:
<?php // use navigation helper to get trail ancestor pages $nh = Loader::helper('navigation'); $pageTrail = $nh->getTrailToCollection($c); // find main product page by traversing up tree (defaults to current page, replaced if a parent has "product" page type) $productMainPage = $c; foreach ($pageTrail as $page) { // if parent page is of our page type (we know it's "Product", but this avoids typos and possible name changes) if ($page->getCollectionTypeHandle() == $c->getCollectionTypeHandle()) { $productMainPage = $page; } } // define a unique global area with the main product page's cID $a = new GlobalArea('Product ' . $productMainPage->cID . ' Sidebar'); $a->setAttribute('add_text', 'Add To Productwide Sidebar'); $a->display($c); ?>
Comments
I want to put it in my package like /packages/my_package/elements/block_area_footer.php
but this way didn't work. it don't overrides the core file
is it possible to do this?
Here is a thread in the C5 forums about how to override core elements in a package (basically you need to call the "OverrideCoreByPackage" function in your package controller's on_start() method):
http://www.concrete5.org/community/forums/customizing_c5/override-core-block-controllers-within-package/
Note the comment in there about not being allowed to use that function in marketplace addons (so it's fine if this is a package you're building for internal use, but not if it's something you want to sell as an addon to others).
Commenting has been disabled.