Source of file MetadataTextField.php
Size: 2,059 Bytes - Last Modified: 2021-12-23T10:25:41+00:00
/var/www/docs.ssmods.com/process/src/code/dataobjects/fields/MetadataTextField.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 | <?php /** * @package silverstripe-metadata */ class MetadataTextField extends MetadataField { private static $db = array( 'Rows' => 'Int', ); private static $defaults = array( 'Rows' => 1 ); public function getFieldTitle() { return 'Text Field'; } protected $processedRecord; public function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldToTab('Root.Options', new NumericField( 'Rows', 'Number of rows' )); $fields->addFieldToTab('Root.Main', new LiteralField( 'KeywordNote', '<p>Keyword replacements in the form "$FieldName"' . ' or "$Member.FieldName" can be used in the default value, as well' . ' as in the actual metadata value. These will be replaced with the' . ' corresponding field from the record the schema is applied to.<p>' )); $fields->dataFieldByName('Default')->setRows(3); return $fields; } /** * @return TextField|TextareaField */ public function getFormField() { if ($rows = $this->Rows > 1) { $field = new TextareaField($this->getFormFieldName(), $this->Title, $this->Rows); } else { $field = new TextField($this->getFormFieldName(), $this->Title); } $field->setRightTitle(sprintf( '<a href="#" class="ss-metadatasetfield-showreplacements">Available keyword replacements</a>' )); return $field; } public function processBeforeWrite($value, $record) { return preg_replace_callback( '/\$Member\.([A-Za-z_][A-Za-z0-9_]*)/', array($this, 'replaceMemberKeyword'), $value); } public function replaceMemberKeyword($matches) { $record = Member::currentUser(); $field = $matches[1]; if ($record && $record->$field) { return $record->$field; } else { return '$Member.' . $field; } } } |