2011-04-15 11:35:30 +02:00
|
|
|
<?php
|
2016-06-15 06:03:16 +02:00
|
|
|
|
|
|
|
namespace SilverStripe\ORM;
|
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Core\Config\Config;
|
|
|
|
use SilverStripe\Core\Extension;
|
|
|
|
use SilverStripe\Forms\FieldList;
|
2020-05-27 23:35:07 +02:00
|
|
|
use SilverStripe\Forms\CompositeValidator;
|
2016-06-15 06:03:16 +02:00
|
|
|
use SilverStripe\ORM\Queries\SQLSelect;
|
2021-04-01 12:36:36 +02:00
|
|
|
use SilverStripe\Security\Member;
|
2016-08-19 00:51:35 +02:00
|
|
|
use Exception;
|
2016-06-15 06:03:16 +02:00
|
|
|
|
2011-04-15 11:35:30 +02:00
|
|
|
/**
|
2012-09-26 23:34:00 +02:00
|
|
|
* An extension that adds additional functionality to a {@link DataObject}.
|
2011-04-15 11:35:30 +02:00
|
|
|
*
|
2016-01-26 04:56:07 +01:00
|
|
|
* @property DataObject $owner
|
2011-04-15 11:35:30 +02:00
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
abstract class DataExtension extends Extension
|
|
|
|
{
|
|
|
|
|
2020-06-11 07:04:45 +02:00
|
|
|
/**
|
2020-06-12 00:19:15 +02:00
|
|
|
* @deprecated 4.7.0 No longer used by internal code
|
2020-06-11 07:04:45 +02:00
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
public static function unload_extra_statics($class, $extension)
|
|
|
|
{
|
|
|
|
throw new Exception('unload_extra_statics gone');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook for extension-specific validation.
|
|
|
|
*
|
|
|
|
* @param ValidationResult $validationResult Local validation result
|
|
|
|
* @throws ValidationException
|
|
|
|
*/
|
|
|
|
public function validate(ValidationResult $validationResult)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Edit the given query object to support queries for this extension
|
|
|
|
*
|
|
|
|
* @param SQLSelect $query Query to augment.
|
|
|
|
* @param DataQuery $dataQuery Container DataQuery for this SQLSelect
|
|
|
|
*/
|
|
|
|
public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the database schema as required by this extension.
|
|
|
|
*
|
|
|
|
* When duplicating a table's structure, remember to duplicate the create options
|
|
|
|
* as well. See {@link Versioned->augmentDatabase} for an example.
|
|
|
|
*/
|
|
|
|
public function augmentDatabase()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Augment a write-record request.
|
|
|
|
*
|
|
|
|
* @param array $manipulation Array of operations to augment.
|
|
|
|
*/
|
|
|
|
public function augmentWrite(&$manipulation)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-06-11 07:04:45 +02:00
|
|
|
/**
|
|
|
|
* Extend the owner's onBeforeWrite() logic
|
|
|
|
*
|
|
|
|
* See {@link DataObject::onBeforeWrite()} for context.
|
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
public function onBeforeWrite()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-06-11 07:04:45 +02:00
|
|
|
/**
|
|
|
|
* Extend the owner's onAfterWrite() logic
|
|
|
|
*
|
|
|
|
* See {@link DataObject::onAfterWrite()} for context.
|
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
public function onAfterWrite()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-06-11 07:04:45 +02:00
|
|
|
/**
|
|
|
|
* Extend the owner's onBeforeDelete() logic
|
|
|
|
*
|
|
|
|
* See {@link DataObject::onBeforeDelete()} for context.
|
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
public function onBeforeDelete()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-06-11 07:04:45 +02:00
|
|
|
/**
|
|
|
|
* Extend the owner's onAfterDelete() logic
|
|
|
|
*
|
|
|
|
* See {@link DataObject::onAfterDelete()} for context.
|
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
public function onAfterDelete()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-06-11 07:04:45 +02:00
|
|
|
/**
|
|
|
|
* Extend the owner's requireDefaultRecords() logic
|
|
|
|
*
|
|
|
|
* See {@link DataObject::requireDefaultRecords()} for context.
|
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
public function requireDefaultRecords()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-06-11 07:04:45 +02:00
|
|
|
/**
|
|
|
|
* Extend the owner's populateDefaults() logic
|
|
|
|
*
|
|
|
|
* See {@link DataObject::populateDefaults()} for context.
|
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
public function populateDefaults()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-06-30 06:56:14 +02:00
|
|
|
/**
|
|
|
|
* Extend the owner's onAfterBuild() logic
|
|
|
|
*
|
|
|
|
* See {@link DataObject::onAfterBuild()} for context.
|
|
|
|
*/
|
|
|
|
public function onAfterBuild()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-06-11 07:04:45 +02:00
|
|
|
/**
|
|
|
|
* Influence the owner's can() permission check value to be disallowed (false),
|
2020-06-12 00:19:15 +02:00
|
|
|
* allowed (true) if no other processed results are to disallow, or open (null) to not
|
|
|
|
* affect the outcome.
|
2020-06-11 07:04:45 +02:00
|
|
|
*
|
|
|
|
* See {@link DataObject::can()} and {@link DataObject::extendedCan()} for context.
|
|
|
|
*
|
|
|
|
* @param Member $member
|
2020-06-12 03:45:14 +02:00
|
|
|
* @return bool|null
|
2020-06-11 07:04:45 +02:00
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
public function can($member)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-06-11 07:04:45 +02:00
|
|
|
/**
|
|
|
|
* Influence the owner's canEdit() permission check value to be disallowed (false),
|
2020-06-12 00:19:15 +02:00
|
|
|
* allowed (true) if no other processed results are to disallow, or open (null) to not
|
|
|
|
* affect the outcome.
|
2020-06-11 07:04:45 +02:00
|
|
|
*
|
|
|
|
* See {@link DataObject::canEdit()} and {@link DataObject::extendedCan()} for context.
|
|
|
|
*
|
|
|
|
* @param Member $member
|
2020-06-12 03:45:14 +02:00
|
|
|
* @return bool|null
|
2020-06-11 07:04:45 +02:00
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
public function canEdit($member)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-06-11 07:04:45 +02:00
|
|
|
/**
|
|
|
|
* Influence the owner's canDelete() permission check value to be disallowed (false),
|
2020-06-12 00:19:15 +02:00
|
|
|
* allowed (true) if no other processed results are to disallow, or open (null) to not
|
|
|
|
* affect the outcome.
|
2020-06-11 07:04:45 +02:00
|
|
|
*
|
|
|
|
* See {@link DataObject::canDelete()} and {@link DataObject::extendedCan()} for context.
|
|
|
|
*
|
|
|
|
* @param Member $member
|
2020-06-12 03:45:14 +02:00
|
|
|
* @return bool|null
|
2020-06-11 07:04:45 +02:00
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
public function canDelete($member)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-06-11 07:04:45 +02:00
|
|
|
/**
|
|
|
|
* Influence the owner's canCreate() permission check value to be disallowed (false),
|
2020-06-12 00:19:15 +02:00
|
|
|
* allowed (true) if no other processed results are to disallow, or open (null) to not
|
|
|
|
* affect the outcome.
|
2020-06-11 07:04:45 +02:00
|
|
|
*
|
|
|
|
* See {@link DataObject::canCreate()} and {@link DataObject::extendedCan()} for context.
|
|
|
|
*
|
|
|
|
* @param Member $member
|
2020-06-12 03:45:14 +02:00
|
|
|
* @return bool|null
|
2020-06-11 07:04:45 +02:00
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
public function canCreate($member)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Define extra database fields
|
|
|
|
*
|
|
|
|
* Return a map where the keys are db, has_one, etc, and the values are
|
|
|
|
* additional fields/relations to be defined.
|
|
|
|
*
|
|
|
|
* @param string $class since this method might be called on the class directly
|
|
|
|
* @param string $extension since this can help to extract parameters to help set indexes
|
|
|
|
* @return array Returns a map where the keys are db, has_one, etc, and
|
|
|
|
* the values are additional fields/relations to be defined.
|
|
|
|
*/
|
|
|
|
public function extraStatics($class = null, $extension = null)
|
|
|
|
{
|
2020-04-20 19:58:09 +02:00
|
|
|
return [];
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function is used to provide modifications to the form in the CMS
|
|
|
|
* by the extension. By default, no changes are made. {@link DataObject->getCMSFields()}.
|
|
|
|
*
|
|
|
|
* Please consider using {@link updateFormFields()} to globally add
|
|
|
|
* formfields to the record. The method {@link updateCMSFields()}
|
|
|
|
* should just be used to add or modify tabs, or fields which
|
|
|
|
* are specific to the CMS-context.
|
|
|
|
*
|
|
|
|
* Caution: Use {@link FieldList->addFieldToTab()} to add fields.
|
|
|
|
*
|
|
|
|
* @param FieldList $fields FieldList with a contained TabSet
|
|
|
|
*/
|
|
|
|
public function updateCMSFields(FieldList $fields)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-02-16 19:26:40 +01:00
|
|
|
/**
|
|
|
|
* This function is used to provide modifications to the Validators used on a DataObject.
|
|
|
|
*
|
2020-05-27 23:35:07 +02:00
|
|
|
* Caution: Use {@link CompositeValidator->addValidator()} to add Validators.
|
2020-02-16 19:26:40 +01:00
|
|
|
*
|
2020-05-27 23:35:07 +02:00
|
|
|
* @param CompositeValidator $compositeValidator
|
2020-02-16 19:26:40 +01:00
|
|
|
*/
|
2020-05-28 02:23:35 +02:00
|
|
|
public function updateCMSCompositeValidator(CompositeValidator $compositeValidator): void
|
2020-02-16 19:26:40 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
/**
|
|
|
|
* This function is used to provide modifications to the form used
|
|
|
|
* for front end forms. {@link DataObject->getFrontEndFields()}
|
|
|
|
*
|
|
|
|
* Caution: Use {@link FieldList->push()} to add fields.
|
|
|
|
*
|
|
|
|
* @param FieldList $fields FieldList without TabSet nesting
|
|
|
|
*/
|
|
|
|
public function updateFrontEndFields(FieldList $fields)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is used to provide modifications to the form actions
|
|
|
|
* used in the CMS. {@link DataObject->getCMSActions()}.
|
|
|
|
*
|
|
|
|
* @param FieldList $actions FieldList
|
|
|
|
*/
|
|
|
|
public function updateCMSActions(FieldList $actions)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* this function is used to provide modifications to the summary fields in CMS
|
|
|
|
* by the extension
|
|
|
|
* By default, the summaryField() of its owner will merge more fields defined in the extension's
|
|
|
|
* $extra_fields['summary_fields']
|
|
|
|
*
|
|
|
|
* @param array $fields Array of field names
|
|
|
|
*/
|
|
|
|
public function updateSummaryFields(&$fields)
|
|
|
|
{
|
2017-05-17 07:40:13 +02:00
|
|
|
$summary_fields = Config::inst()->get(static::class, 'summary_fields');
|
2016-11-29 00:31:16 +01:00
|
|
|
if ($summary_fields) {
|
|
|
|
// if summary_fields were passed in numeric array,
|
|
|
|
// convert to an associative array
|
|
|
|
if ($summary_fields && array_key_exists(0, $summary_fields)) {
|
|
|
|
$summary_fields = array_combine(array_values($summary_fields), array_values($summary_fields));
|
|
|
|
}
|
|
|
|
if ($summary_fields) {
|
|
|
|
$fields = array_merge($fields, $summary_fields);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* this function is used to provide modifications to the fields labels in CMS
|
|
|
|
* by the extension
|
|
|
|
* By default, the fieldLabels() of its owner will merge more fields defined in the extension's
|
|
|
|
* $extra_fields['field_labels']
|
|
|
|
*
|
|
|
|
* @param array $labels Array of field labels
|
|
|
|
*/
|
|
|
|
public function updateFieldLabels(&$labels)
|
|
|
|
{
|
2017-05-17 07:40:13 +02:00
|
|
|
$field_labels = Config::inst()->get(static::class, 'field_labels');
|
2016-11-29 00:31:16 +01:00
|
|
|
if ($field_labels) {
|
|
|
|
$labels = array_merge($labels, $field_labels);
|
|
|
|
}
|
|
|
|
}
|
2011-04-15 11:35:30 +02:00
|
|
|
}
|