| 1 | <?php |
||
| 8 | class ConfigurablePageFieldExtension extends DataExtension |
||
| 9 | { |
||
| 10 | private static $belongs_many_many = [ |
||
| 11 | 'Parents' => 'ConfigurablePage', |
||
| 12 | ]; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Get field value that is suitable for the view template file. |
||
| 16 | * |
||
| 17 | * @return object|false|string |
||
| 18 | */ |
||
| 19 | 2 | public function getViewValue() |
|
| 20 | { |
||
| 21 | 2 | $class = $this->owner; |
|
| 22 | |||
| 23 | // Header field only used in page type |
||
| 24 | 2 | if ($class instanceof Moo_EditableFieldHeading) { |
|
| 25 | 1 | return false; |
|
| 26 | } |
||
| 27 | |||
| 28 | // Default return string |
||
| 29 | 1 | return (string) $this->owner->Value; |
|
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Get string value of a field. |
||
| 34 | * |
||
| 35 | * @return null|string |
||
| 36 | */ |
||
| 37 | 1 | public function getValueAsString() |
|
| 38 | { |
||
| 39 | 1 | return (string) $this->owner->Value; |
|
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Format the field Title to be suitable as a variable in template. |
||
| 44 | * |
||
| 45 | * @return string |
||
| 46 | */ |
||
| 47 | 2 | public function getViewFieldName() |
|
| 48 | { |
||
| 49 | 2 | return $this->owner->Name; |
|
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Editable field can only be changed if is not part of a group. |
||
| 54 | * |
||
| 55 | * @param null $member |
||
| 56 | * |
||
| 57 | * @return bool |
||
| 58 | */ |
||
| 59 | public function canEdit($member = null) |
||
| 63 | } |
||
| 64 |