Ejemplo n.º 1
0
 /**
  * Gets the field editor, for adding and removing EditableFormFields.
  *
  * @return GridField
  */
 public function getFieldEditorGrid()
 {
     Requirements::javascript(USERFORMS_DIR . '/javascript/FieldEditor.js');
     $fields = $this->Fields();
     $editableColumns = new GridFieldEditableColumns();
     $fieldClasses = singleton('EditableFormField')->getEditableFieldClasses();
     $editableColumns->setDisplayFields(array('ClassName' => function ($record, $column, $grid) use($fieldClasses) {
         if ($record instanceof EditableFormField) {
             return $record->getInlineClassnameField($column, $fieldClasses);
         }
     }, 'Title' => function ($record, $column, $grid) {
         if ($record instanceof EditableFormField) {
             return $record->getInlineTitleField($column);
         }
     }));
     $config = GridFieldConfig::create()->addComponents($editableColumns, new GridFieldButtonRow(), GridFieldAddClassesButton::create('EditableTextField')->setButtonName(_t('UserFormFieldEditorExtension.ADD_FIELD', 'Add Field'))->setButtonClass('ss-ui-action-constructive'), GridFieldAddClassesButton::create('EditableFormStep')->setButtonName(_t('UserFormFieldEditorExtension.ADD_PAGE_BREAK', 'Add Page Break')), GridFieldAddClassesButton::create(array('EditableFieldGroup', 'EditableFieldGroupEnd'))->setButtonName(_t('UserFormFieldEditorExtension.ADD_FIELD_GROUP', 'Add Field Group')), new GridFieldEditButton(), new GridFieldDeleteAction(), new GridFieldToolbarHeader(), new GridFieldDetailForm());
     $fieldEditor = GridField::create('Fields', _t('UserDefinedForm.FIELDS', 'Fields'), $fields, $config)->addExtraClass('uf-field-editor');
     if (Config::inst()->get('UserFormFieldEditorExtension', 'showAddEdit')) {
         $addFieldAction->setTitle(_t('UserFormFieldEditorExtension.ADD_EDIT_FIELD', 'Add & Edit Field'));
         $fields = $addFieldAction->getClasses($fieldEditor);
         $fields = array_diff_key($fields, array_flip(array('EditableFormStep', 'EditableFieldGroup', 'EditableFieldGroupEnd')));
         asort($fields);
         $addFieldAction->setClasses($fields);
     }
     return $fieldEditor;
 }
 /**
  * Gets the field editor, for adding and removing EditableFormFields.
  *
  * @return GridField
  */
 public function getFieldEditorGrid()
 {
     Requirements::javascript('pageblockbuilder/javascript/FieldEditor.js');
     $editableColumns = new GridFieldEditableColumns();
     $fieldClasses = singleton('EditableFormField')->getEditableFieldClasses();
     $editableColumns->setDisplayFields(array('ClassName' => function ($record, $column, $grid) use($fieldClasses) {
         if ($record instanceof EditableFormField) {
             return $record->getInlineClassnameField($column, $fieldClasses);
         }
     }, 'Title' => function ($record, $column, $grid) {
         if ($record instanceof EditableFormField) {
             return $record->getInlineTitleField($column);
         }
     }));
     $config = GridFieldConfig::create()->addComponents($editableColumns, new GridFieldButtonRow(), GridFieldAddClassesButton::create('EditableTextField')->setButtonName('Add Block')->setButtonClass('ss-ui-action-constructive'), new GridFieldEditButton(), new GridFieldDeleteAction(), new GridFieldToolbarHeader(), new GridFieldOrderableRows('SortOrder'), new GridFieldDetailForm());
     $fieldEditor = GridField::create('Fields', 'Fields', $this->owner->Blocks(), $config)->addExtraClass('uf-field-editor');
     return $fieldEditor;
 }