本文整理汇总了PHP中FieldList::setForm方法的典型用法代码示例。如果您正苦于以下问题:PHP FieldList::setForm方法的具体用法?PHP FieldList::setForm怎么用?PHP FieldList::setForm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FieldList
的用法示例。
在下文中一共展示了FieldList::setForm方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Create a new form, with the given fields an action buttons.
*
* @param Controller $controller The parent controller, necessary to create the appropriate form action tag.
* @param String $name The method on the controller that will return this form object.
* @param FieldList $fields All of the fields in the form - a {@link FieldList} of {@link FormField} objects.
* @param FieldList $actions All of the action buttons in the form - a {@link FieldLis} of
* {@link FormAction} objects
* @param Validator $validator Override the default validator instance (Default: {@link RequiredFields})
*/
public function __construct($controller, $name, FieldList $fields, FieldList $actions, $validator = null)
{
parent::__construct();
if (!$fields instanceof FieldList) {
throw new InvalidArgumentException('$fields must be a valid FieldList instance');
}
if (!$actions instanceof FieldList) {
throw new InvalidArgumentException('$actions must be a valid FieldList instance');
}
if ($validator && !$validator instanceof Validator) {
throw new InvalidArgumentException('$validator must be a Validator instance');
}
$fields->setForm($this);
$actions->setForm($this);
$this->fields = $fields;
$this->actions = $actions;
$this->controller = $controller;
$this->name = $name;
if (!$this->controller) {
user_error("{$this->class} form created without a controller", E_USER_ERROR);
}
// Form validation
$this->validator = $validator ? $validator : new RequiredFields();
$this->validator->setForm($this);
// Form error controls
$this->setupFormErrors();
// Check if CSRF protection is enabled, either on the parent controller or from the default setting. Note that
// method_exists() is used as some controllers (e.g. GroupTest) do not always extend from Object.
if (method_exists($controller, 'securityTokenEnabled') || method_exists($controller, 'hasMethod') && $controller->hasMethod('securityTokenEnabled')) {
$securityEnabled = $controller->securityTokenEnabled();
} else {
$securityEnabled = SecurityToken::is_enabled();
}
$this->securityToken = $securityEnabled ? new SecurityToken() : new NullSecurityToken();
}
示例2: getRecordDataFields
//.........这里部分代码省略.........
}
} else {
$recordSectionTitle = $record->{$titleFieldName};
}
if (!$recordSectionTitle) {
// NOTE(Jake): Ensures no title'd ToggleCompositeField's have a proper height.
$recordSectionTitle = ' ';
}
$recordSectionTitle .= ' <span class="js-multirecordfield-title-status">';
$recordSectionTitle .= $status ? '(' . $status . ')' : '';
$recordSectionTitle .= '</span>';
// Add heading field / Togglable composite field with heading
$subRecordField = MultiRecordSubRecordField::create('', $recordSectionTitle, null);
$subRecordField->setParent($this);
$subRecordField->setRecord($record);
if ($this->readonly) {
$subRecordField = $subRecordField->performReadonlyTransformation();
}
// Modify sub-fields to work properly with this field
$currentFieldListModifying = $subRecordField;
foreach ($fields as $field) {
$fieldName = $field->getName();
if ($recordShouldSetValue) {
if (isset($record->{$fieldName}) || $record->hasMethod($fieldName) || $record->hasMethod('hasField') && $record->hasField($fieldName)) {
$val = $record->__get($fieldName);
$field->setValue($val, $record);
}
}
if ($field instanceof MultiRecordField) {
$field->depth = $this->depth + 1;
$action = $this->getActionURL($field, $record);
$field->setAttribute('data-action', $action);
// NOTE(Jake): Unclear at time of writing (17-06-2016) if nested MultiRecordField should
// inherit certain settings or not. Might add flag like 'setRecursiveOptions' later
// or something.
$field->setFieldsFunction($this->getFieldsFunction(), $this->fieldsFunctionFallback);
//$field->setTitleField($this->getTitleField());
} else {
$config = $this->getConfig();
if ($config === null) {
$config = $this->config()->default_config;
}
// todo(Jake): Make it walk class hierarchy so that things that extend say 'HtmlEditorField'
// will also get the config. Make the '*HtmlEditorField' denote that it's only
// for that class, sub-classes.
if (isset($config[$field->class])) {
$fieldConfig = $config[$field->class];
$functionCalls = isset($fieldConfig['functions']) ? $fieldConfig['functions'] : array();
if ($functionCalls) {
foreach ($functionCalls as $methodName => $arguments) {
$arguments = (array) $arguments;
call_user_func_array(array($field, $methodName), $arguments);
}
}
}
if ($field instanceof FileAttachmentField) {
// fix(Jake)
// todo(Jake): Fix deletion
// Support for Unclecheese's Dropzone module
// @see: https://github.com/unclecheese/silverstripe-dropzone/tree/1.2.3
$action = $this->getActionURL($field, $record);
$field = MultiRecordFileAttachmentField::cast($field);
$field->multiRecordAction = $action;
// Fix $field->Value()
if ($recordShouldSetValue && !$val && isset($record->{$fieldName . 'ID'})) {
// NOTE(Jake): This check was added for 'FileAttachmentField'.
// Putting this outside of this 'instanceof' if-statement will break UploadField.
$val = $record->__get($fieldName . 'ID');
if ($val) {
$field->setValue($val, $record);
}
}
} else {
if (class_exists('MultiRecord' . $field->class)) {
// Handle generic case (ie. UploadField)
// Where we just want to override value returned from $field->Link()
// so FormField actions work.
$class = 'MultiRecord' . $field->class;
$fieldCopy = $class::create($field->getName(), $field->Title());
foreach (get_object_vars($field) as $property => $value) {
$fieldCopy->{$property} = $value;
}
$fieldCopy->multiRecordAction = $this->getActionURL($field, $record);
$field = $fieldCopy;
}
}
// NOTE(Jake): Should probably add an ->extend() so other modules can monkey patch fields.
// Will wait to see if its needed.
}
// NOTE(Jake): Required to support UploadField. Generic so any field can utilize this functionality.
if (method_exists($field, 'setRecord') || method_exists($field, 'hasMethod') && $field->hasMethod('setRecord')) {
$field->setRecord($record);
}
$currentFieldListModifying->push($field);
}
$resultFieldList = new FieldList();
$resultFieldList->push($subRecordField);
$resultFieldList->setForm($this->form);
return $resultFieldList;
}