Source of file ContactItem.php
Size: 7,096 Bytes - Last Modified: 2021-12-23T10:36:44+00:00
/var/www/docs.ssmods.com/process/src/src/Model/ContactItem.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 | <?php /** * This file is part of SilverWare. * * PHP version >=5.6.0 * * For full copyright and license information, please view the * LICENSE.md file that was distributed with this source code. * * @package SilverWare\Contact\Model * @author Colin Tucker <colin@praxis.net.au> * @copyright 2017 Praxis Interactive * @license https://opensource.org/licenses/BSD-3-Clause BSD-3-Clause * @link https://github.com/praxisnetau/silverware-contact */ namespace SilverWare\Contact\Model; use SilverStripe\Forms\CheckboxField; use SilverStripe\Forms\RequiredFields; use SilverWare\FontIcons\Extensions\FontIconExtension; use SilverWare\Forms\FieldSection; use SilverWare\Model\Component; /** * An extension of the component class for a contact item. * * @package SilverWare\Contact\Model * @author Colin Tucker <colin@praxis.net.au> * @copyright 2017 Praxis Interactive * @license https://opensource.org/licenses/BSD-3-Clause BSD-3-Clause * @link https://github.com/praxisnetau/silverware-contact */ class ContactItem extends Component { /** * Human-readable singular name. * * @var string * @config */ private static $singular_name = 'Item'; /** * Human-readable plural name. * * @var string * @config */ private static $plural_name = 'Items'; /** * Description of this object. * * @var string * @config */ private static $description = 'A component which represents a contact item'; /** * Defines the table name to use for this object. * * @var string * @config */ private static $table_name = 'SilverWare_ContactItem'; /** * Icon file for this object. * * @var string * @config */ private static $icon = 'silverware/contact: admin/client/dist/images/icons/ContactItem.png'; /** * Defines an ancestor class to hide from the admin interface. * * @var string * @config */ private static $hide_ancestor = Component::class; /** * Defines the allowed children for this object. * * @var array|string * @config */ private static $allowed_children = 'none'; /** * Maps field names to field types for this object. * * @var array * @config */ private static $db = [ 'HideTitle' => 'Boolean' ]; /** * Defines the default values for the fields of this object. * * @var array * @config */ private static $defaults = [ 'HideTitle' => 0 ]; /** * Defines the extension classes to apply to this object. * * @var array * @config */ private static $extensions = [ FontIconExtension::class ]; /** * Answers a list of field objects for the CMS interface. * * @return FieldList */ public function getCMSFields() { // Obtain Field Objects (from parent): $fields = parent::getCMSFields(); // Create Options Fields: $fields->addFieldsToTab( 'Root.Options', [ FieldSection::create( 'TitleOptions', $this->fieldLabel('TitleOptions'), [ CheckboxField::create( 'HideTitle', $this->fieldLabel('HideTitle') ) ] ) ] ); // Answer Field Objects: return $fields; } /** * Answers a validator for the CMS interface. * * @return RequiredFields */ public function getCMSValidator() { return RequiredFields::create([ 'Title' ]); } /** * Answers the labels for the fields of the receiver. * * @param boolean $includerelations Include labels for relations. * * @return array */ public function fieldLabels($includerelations = true) { // Obtain Field Labels (from parent): $labels = parent::fieldLabels($includerelations); // Define Field Labels: $labels['HideTitle'] = _t(__CLASS__ . '.HIDETITLE', 'Hide title'); $labels['TitleOptions'] = _t(__CLASS__ . '.TITLE', 'Title'); // Answer Field Labels: return $labels; } /** * Answers the heading tag for the receiver. * * @return string */ public function getHeadingTag() { return $this->getParent()->HeadingTag; } /** * Answers the item tag for the receiver. * * @return string */ public function getItemTag() { return $this->IsListItem ? 'li' : 'section'; } /** * Answers true if the receiver is a list item. * * @return boolean */ public function getIsListItem() { return (($parent = $this->getParent()) && $parent->IsList); } /** * Answers true if the font icon is to be shown. * * @return boolean */ public function getShowIcon() { if ($parent = $this->getParent()) { return (boolean) $parent->ShowIcons; } } /** * Answers true if the title text is to be shown. * * @return boolean */ public function getShowText() { if ($parent = $this->getParent()) { return !$parent->HideTitles; } } /** * Answers true if the title is to be shown in the template. * * @return boolean */ public function getShowTitle() { return !$this->HideTitle; } /** * Answers true to enable fixed width mode. * * @return boolean */ public function getFontIconFixedWidth() { return true; } /** * Answers true to enable list item mode. * * @return boolean */ public function getFontIconListItem() { return $this->IsListItem; } /** * Answers null to avoid problems with '$Content' double-ups in the template. * * @return null */ public function getContent() { return null; } /** * Renders the object for the HTML template. * * @param string $layout Page layout passed from template. * @param string $title Page title passed from template. * * @return DBHTMLText|string */ public function renderSelf($layout = null, $title = null) { return $this->customise([ 'Content' => $this->renderContent() ])->renderWith(self::class); } /** * Renders the content for the HTML template. * * @return DBHTMLText|string */ public function renderContent() { if ($this->getTemplate() != self::class) { return $this->renderWith($this->getTemplate()); } } } |