当前位置: 首页>>代码示例>>PHP>>正文


PHP FieldList::setForm方法代码示例

本文整理汇总了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();
 }
开发者ID:prostart,项目名称:erics-homes,代码行数:45,代码来源:Form.php

示例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;
 }
开发者ID:silbinarywolf,项目名称:multirecordfield,代码行数:101,代码来源:MultiRecordField.php


注:本文中的FieldList::setForm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。