Source of file DBComponentField.php
Size: 2,758 Bytes - Last Modified: 2021-12-23T10:49:25+00:00
/var/www/docs.ssmods.com/process/src/src/Symbiote/Components/DBComponentField.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 | <?php namespace Symbiote\Components; use Exception; use SilverStripe\ORM\FieldType\DBText; use SilverStripe\ORM\FieldType\DBField; use SilverStripe\ORM\SS_List; use SilverStripe\View\ViewableData; class DBComponentField extends DBText { /** * Workaround a "bug" in SilverStripe 3.X where * attributes aren't cast as HTMLText and don't * escape. * * NOTE: * We may re-introduce this feature in SS 4.X * if it proves to be useful. * * @var array */ //private static $text_property_casting = array( // 'getAttributesHTML' => true, //); /** * Store the objects passed into a component property. * * @var ViewableData[] */ protected $fields = array(); public function __construct($name, array $fields) { parent::__construct($name); $this->fields = $fields; // Set value from fields $value = ''; //$textPropertyCasting = $this->config()->text_property_casting; foreach ($this->fields as $i => $field) { if (!is_object($field)) { $value .= $field; continue; } if (!$field->hasMethod('forTemplate')) { if ($field instanceof SS_List) { throw new Exception("Cannot use SS_List type with other field parts. (Make sure there are no spaces around the quotes) for component property \"$name\"."); } throw new Exception("Missing forTemplate() on field part #$i for component property \"$name\"."); } //if (get_class($field) === 'Text') { // if ($textPropertyCasting && // isset($textPropertyCasting[$field->getName()])) { // $value .= $field->getValue(); // continue; // } //} $value .= $field->forTemplate(); } $this->value = $value; } /** * Stop default behaviour, which is escaping to XML. * * @return string|SS_List */ public function forTemplate() { return $this->getValue(); } /** * (non-PHPdoc) * * @see DBField::requireField() */ public function requireField() { throw new Exception('Do not use this as a database field.'); } /** * @param DBField $field * @return string|null */ /*private function propertyCasting($field) { if (get_class($field) === 'Text') { if ($textPropertyCasting && isset($textPropertyCasting[$field->getName()])) { return $field->getValue(); continue; } } return null; }*/ } |