Wallogit.com
2017 © Pedro Peláez
Helper classes for Concrete5 V8
Use in place of Concrete\Core\Block\BlockController,
implementing schemaType() and schemaProperties($fieldData) methods., (*1)
e.g, (*2)
namespace Concrete\Package\Extrablocks\Block\Contactdetails;
use Helper\LdJson\LDJsonBlockController;
class Controller extends LDJsonBlockController
{
protected $btTable = ' ... ';
public function getBlockTypeName() { ... }
public function getBlockTypeDescription() { ... }
protected function schemaType() : string {
return "ContactPoint";
}
protected function schemaProperties($fieldData) : array {
// $fielddata contains the row from the BlockTypeController's table
$name = trim($fieldData['honorific'] . ' ' .
$fieldData['firstName'] . ' ' . $fieldData['lastName']);
$data = [];
$data['name'] = $name;
$data['areaServed'] = $this->makeSchemaProperty(
'AdministrativeArea',
['address' => '123 bonsqde st, Wellington',
'branchCode'=> 'JW001']
);
if ($fieldData['email']) {
$data['email'] = $fieldData['email'];
}
if ($fieldData['phone']) {
$data['telephone'] = $fieldData['phone'];
}
if ($fieldData['fax']) {
$data['fax'] = $fieldData['fax'];
}
return $data;
}
public function view($args) {...}
public function validate($args) {...}
}
In view.php, add:, (*3)
<?php
echo $LDJson;
?>
Use in place of Concrete\Core\Block\BlockController,
implementing schemaType() and schemaProperties($fieldData) methods., (*4)
e.g, (*5)
namespace Concrete\Package\Extrablocks\Block\Contactdetails;
use Helper\LdJson\LDJsonBlockController;
class Full extends PageTypeController
{
public function on_start() { ... }
protected function schemaType() : string {
return "LocalBusiness";
}
protected function schemaProperties($fieldData) : array {
// $fielddata is null
$data = [];
$data['name'] = $name;
return $data;
}
public function view($args) {...}
}
In view.php, add:, (*6)
<?php
echo $LDJson;
?>
Helps restrict an Area to a single block of a single BlockType by adding a block of the type, and removing delete Permissions for specified groups. Requires advanced permissions to be enabled., (*7)
In the template, business as usual:, (*8)
<?php
$a = new Area('Header');
$a->setAreaDisplayName('Header');
$a->setBlockLimit(1);
$a->display($c);
?>
In the controller, the following snippet adds an 'image' blockttype to the 'Header' area if the area is empty, removing delete permissions for 'Administrators' and 'Editors' groups., (*9)
NB Administrators will still be able to delete the block and replace it with something else. Creating a separate group as such Editors will make this work., (*10)
use Helper\Block\RestrictAreaBlockType; class Home extends PageTypeController { public function on_start() { ... } public function view() { $imageArea = Area::get($this->page, 'Header'); if ($imageArea) { RestrictAreaBlockType::restrictPageAreaBlockType ($this->page, Area::get($this->page, 'Header'), 'image', ['Editors', 'Administrators']); } // ... any other code ... } }