Returns the GridField_FormAction if archive can be performed

@param GridField $gridField
@param DataObject $record
@return GridField_FormAction|null
493988
public function getArchiveAction($gridField, $record)
    {
        /* @var DataObject|Versioned $record */
        if (!$record->hasMethod('canArchive') || !$record->canArchive()) {
            return null;
        }

        $title = _t(__CLASS__ . '.Archive', "Archive");

        $field = GridField_FormAction::create(
            $gridField,
            'ArchiveRecord' . $record->ID,
            false,
            "archiverecord",
            ['RecordID' => $record->ID]
        )
            ->addExtraClass('action--archive btn--icon-md font-icon-box btn--no-text grid-field__icon-action action-menu--handled')
            ->setAttribute('classNames', 'action--archive font-icon-box')
            ->setDescription($title)
            ->setAttribute('aria-label', $title);

        return $field;
    }
632426
public function create($entity, $record = null, $child = null)
    {
        if (!$record && !$child && ($entityObject = Entity::fromYamlFile($entity))) {
            $form = new Form($entityObject, null, Session::get('errors'));

            return $form->view();
        } elseif (($parentEntity = Entity::fromYamlFile($entity)) && ($entityObject = Entity::fromYamlFile($child))) {
            // Get parent's record
            $parentRecord = $parentEntity->class::findOrFail($record);

            $form = new Form($entityObject, null, Session::get('errors'), $parentEntity, $parentRecord);

            return $form->view();
        } else {
            abort(404);
        }
    }
177160
public function get_document($record, $options = array()) {
        try {
            $cm = $this->get_cm('wiki', $record->wikiid, $record->courseid);
            $context = \context_module::instance($cm->id);
        } catch (\dml_missing_record_exception $ex) {
            // Notify it as we run here as admin, we should see everything.
            debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document, not all required data is available: ' .
                $ex->getMessage(), DEBUG_DEVELOPER);
            return false;
        } catch (\dml_exception $ex) {
            // Notify it as we run here as admin, we should see everything.
            debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document: ' . $ex->getMessage(), DEBUG_DEVELOPER);
            return false;
        }

        // Make a page object without extra fields.
        $page = clone $record;
        unset($page->courseid);
        unset($page->wikiid);

        // Conversion based wiki_print_page_content().
        // Check if we have passed the cache time.
        if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) {
            $content = wiki_refresh_cachedcontent($page);
            $page = $content['page'];
        }
        // Convert to text.
        $content = content_to_text($page->cachedcontent, FORMAT_MOODLE);

        // Prepare associative array with data from DB.
        $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname);
        $doc->set('title', content_to_text($record->title, false));
        $doc->set('content', $content);
        $doc->set('contextid', $context->id);
        $doc->set('courseid', $record->courseid);
        if ($record->groupid > 0) {
            $doc->set('groupid', $record->groupid);
        }
        $doc->set('owneruserid', \core_search\manager::NO_OWNER_ID);
        $doc->set('modified', $record->timemodified);

        // Check if this document should be considered new.
        if (isset($options['lastindexedtime']) && ($options['lastindexedtime'] < $record->timecreated)) {
            // If the document was created after the last index time, it must be new.
            $doc->set_is_new(true);
        }

        return $doc;
    }
1210554
public function getRecordAction(Request $request, $databox_id, $record_id)
    {
        try {
            $record = $this->findDataboxById($databox_id)->get_record($record_id);

            return Result::create($request, ['record' => $this->listRecord($request, $record)])->createResponse();
        } catch (NotFoundHttpException $e) {
            return Result::createError($request, 404, $this->app->trans('Record Not Found'))->createResponse();
        } catch (\Exception $e) {
            return $this->getBadRequestAction($request, $this->app->trans('An error occurred'));
        }
    }
743285
public function getManipulatedData(GridField $gridField, SS_List $dataList)
    {
        if (!$this->checkDataType($dataList)) {
            return $dataList;
        }

        /** @var Sortable $dataList */
        $state = $gridField->State->GridFieldSortableHeader;
        if ($state->SortColumn == "") {
            return $dataList;
        }

        return $dataList->sort($state->SortColumn, $state->SortDirection('asc'));
    }
233730
public function bulkUploadField($gridField)
    {
        $fileRelationName = $this->getFileRelationName($gridField);
        $fieldName = $fileRelationName . '_' . $this->getRecordClassName($gridField) . '_BU';
        $uploadField = BulkUploadField::create($gridField, $fieldName, '')
            ->setForm($gridField->getForm())
            ->setRecord(DataObject::create()) // avoid UploadField to get auto-config from the Page (e.g fix allowedMaxFileNumber)
            ;

        //UploadField setup
        foreach ($this->ufSetup as $fn => $param) {
            $uploadField->{$fn}($param);
        }

        $schema['data']['createFileEndpoint'] = [
            'url' => $gridField->Link('bulkupload/upload'),
            'method' => 'post',
            'payloadFormat' => 'urlencoded',
        ];

        $schema['data']['attachFileEndpoint'] = [
            'url' => $gridField->Link('bulkupload/attach'),
            'method' => 'post'
        ];

        $uploadField->setSchemaData($schema);

        return $uploadField;
    }
980394
protected function addVersionedButtons(DataObject $record, FieldList $actions)
    {
        // Save & Publish action
        if ($record->canPublish()) {
            // "publish", as with "save", it supports an alternate state to show when action is needed.
            $publish = FormAction::create(
                'doPublish',
                _t(__CLASS__ . '.BUTTONPUBLISH', 'Publish')
            )
                ->setUseButtonTag(true)
                ->addExtraClass('btn btn-primary font-icon-rocket');

            // Insert after save
            if ($actions->fieldByName('action_doSave')) {
                $actions->insertAfter('action_doSave', $publish);
            } else {
                $actions->push($publish);
            }
        }

        // Unpublish action
        if ($record->isInDB() && $record->canUnpublish()) {
            /** @var DataObject|Versioned|RecursivePublishable $liveRecord */
            $liveRecord = Versioned::get_by_stage($record->baseClass(), Versioned::LIVE)
                ->byID($record->ID);
            if ($liveRecord) {
                $liveOwners = $liveRecord->findOwners(false)->count();
                $actions->push(
                    FormAction::create(
                        'doUnpublish',
                        _t(__CLASS__ . '.BUTTONUNPUBLISH', 'Unpublish')
                    )
                        ->setUseButtonTag(true)
                        ->setDescription(_t(
                            __CLASS__ . '.BUTTONUNPUBLISHDESC',
                            'Remove this record from the published site'
                        ))
                        ->addExtraClass('btn-secondary')
                        ->setAttribute('data-owners', $liveOwners)
                );
            }
        }

        // Archive action
        if ($record->isInDB() && $record->canArchive()) {
            // Replace "delete" action
            $actions->removeByName('action_doDelete');

            // "archive"
            $actions->push(
                FormAction::create('doArchive', _t(__CLASS__ . '.ARCHIVE', 'Archive'))
                    ->setUseButtonTag(true)
                    ->setDescription(_t(
                        __CLASS__ . '.BUTTONARCHIVEDESC',
                        'Unpublish and send to archive'
                    ))
                    ->addExtraClass('btn-secondary action--archive font-icon-box')
            );
        }
    }
1156493
protected function genericHandle($dataFormatterClass, $ext, GridField $gridField, $request = null)
    {
        $items = $this->getItems($gridField);

        $this->setHeader($gridField, $ext);


        $formater = new $dataFormatterClass();
        $formater->setUseLabelsAsHeaders($this->useLabelsAsHeaders);

        $fileData = $formater->convertDataObjectSet($items);

        return $fileData;
    }
857547
protected function getRecordState($record)
    {
        if ($this->isVersioned()) {
            // Check stage this record belongs to
            $stage = $record->getSourceQueryParam('Versioned.stage') ?: Versioned::get_stage();

            // Non-live stages are automatically non-public
            if ($stage !== Versioned::LIVE) {
                return AssetManipulationList::STATE_PROTECTED;
            }
        }

        // Check if canView permits anonymous viewers
        return Member::actAs(null, function () use ($record) {
            return $record->canView()
                ? AssetManipulationList::STATE_PUBLIC
                : AssetManipulationList::STATE_PROTECTED;
        });
    }
778325
protected function getFormattedSelection(ViewableData $record)
    {
        if ($format = $this->getFormatSelection()) {
            return SSViewer::fromString($format)->process($record);
        }
    }
1373487
private function listRecordMetadata(\record_adapter $record)
    {
        $includeBusiness = $this->getAclForUser()->can_see_business_fields($record->getDatabox());

        return $this->listRecordCaptionFields($record->get_caption()->get_fields(null, $includeBusiness));
    }
570799
protected function getFormActions()
    {
        $actions = new FieldList();

        if ($this->record->ID !== 0) { // existing record
            if ($this->record->canEdit()) {
                $actions->push(FormAction::create('doSave', _t('SilverStripe\\Forms\\GridField\\GridFieldDetailForm.Save', 'Save'))
                    ->setUseButtonTag(true)
                    ->addExtraClass('btn-primary font-icon-save'));
            }

            if ($this->record->canDelete()) {
                $actions->push(FormAction::create('doDelete', _t('SilverStripe\\Forms\\GridField\\GridFieldDetailForm.Delete', 'Delete'))
                    ->setUseButtonTag(true)
                    ->addExtraClass('btn-outline-danger btn-hide-outline font-icon-trash-bin action--delete'));
            }

            $gridState = $this->getRequest()->requestVar('gridState');
            $this->gridField->getState(false)->setValue($gridState);
            $actions->push(HiddenField::create('gridState', null, $gridState));

            $actions->push($this->getRightGroupField());
        } else { // adding new record
            //Change the Save label to 'Create'
            $actions->push(FormAction::create('doSave', _t('SilverStripe\\Forms\\GridField\\GridFieldDetailForm.Create', 'Create'))
                ->setUseButtonTag(true)
                ->addExtraClass('btn-primary font-icon-plus-thin'));

            // Add a Cancel link which is a button-like link and link back to one level up.
            $crumbs = $this->Breadcrumbs();
            if ($crumbs && $crumbs->count() >= 2) {
                $oneLevelUp = $crumbs->offsetGet($crumbs->count() - 2);
                $text = sprintf(
                    "<a class=\"%s\" href=\"%s\">%s</a>",
                    "crumb btn btn-secondary cms-panel-link", // CSS classes
                    $oneLevelUp->Link, // url
                    _t('SilverStripe\\Forms\\GridField\\GridFieldDetailForm.CancelBtn', 'Cancel') // label
                );
                $actions->push(new LiteralField('cancelbutton', $text));
            }
        }

        $this->extend('updateFormActions', $actions);

        return $actions;
    }
422289
public function getColumnContent($gridField, $record, $columnName)
    {
        if ($columnName === self::CHECKBOX_COLUMN) {
            return '<input class="multiselect no-change-track" type="checkbox"
					name="' . $columnName . '[' . $record->ID . ']"
					value="' . $record->ID . '">';
        } else {
            return null;
        }
    }
361386
public function getRecordOnClick($record)
    {
        if (!isset($this->recordOnClick)) {
            return null;
        }

        $recordOnClick = RouterHelper::replaceParameters($record, $this->recordOnClick);
        return Html::attributes(['onclick' => $recordOnClick]);
    }
383651
public function handleAction(GridField $gridField, $actionName, $arguments, $data)
    {
        if ($actionName == 'add') {
            $dbField = $this->getDataObjectField();

            $objClass = $gridField->getModelClass();

            /**
             * @var DataObject $obj
             */
            $obj = $objClass::create();

            if ($obj->hasField($dbField)) {
                $obj->setCastedField($dbField, $data['gridfieldaddbydbfield'][$obj->ClassName][$dbField]);

                if ($obj->canCreate()) {
                    $id = $gridField->getList()->add($obj);
                    if (!$id) {
                        $gridField->setCustomValidationMessage(
                            _t(
                                __CLASS__ . '.AddFail',
                                'Unable to save {class} to the database.',
                                'Unable to add the DataObject.',
                                [
                                    'class' => get_class($obj),
                                ]
                            )
                        );
                    }
                } else {
                    return Security::permissionFailure(
                        Controller::curr(),
                        _t(
                            __CLASS__ . '.PermissionFail',
                            'You don\'t have permission to create a {class}.',
                            'Unable to add the DataObject.',
                            [
                                'class' => get_class($obj)
                            ]
                        )
                    );
                }
            } else {
                throw new UnexpectedValueException(
                    sprintf(
                        'Invalid field (%s) on %s.',
                        $dbField,
                        $obj->ClassName
                    )
                );
            }
        }

        return null;
    }
70342
public function getManipulatedData(GridField $gridField, SS_List $dataList)
    {

        if (!$gridField->State->GridFieldAddRelation) {
            return $dataList;
        }

        $objectID = Convert::raw2sql($gridField->State->GridFieldAddRelation);

        if ($objectID) {
            $object = DataObject::get_by_id($dataList->dataclass(), $objectID);

            if ($object) {
                // if the object is currently not linked to either a page or another list then we want to link to
                // the original, otherwise link to a clone
                if (!$object->ParentID) {
                    $dataList->add($object);
                } else {
                    $virtual = ElementVirtual::create();
                    $virtual->LinkedElementID = $object->ID;
                    $virtual->write();

                    $dataList->add($virtual);
                }
            }
        }

        $gridField->State->GridFieldAddRelation = null;

        return $dataList;
    }
584106
protected function getFormFieldDetailsTab($record, $context = [])
    {
        /** @var Tab $tab */
        $tab = Tab::create(
            'Details',
            TextField::create('Name', _t(__CLASS__.'.FILENAME', 'Filename')),
            $location = TreeDropdownField::create(
                'ParentID',
                _t(__CLASS__.'.FOLDERLOCATION', 'Location'),
                Folder::class
            )
                ->setShowSelectedPath(true)
        );

        $location
            ->setEmptyString(_t(__CLASS__.'.ROOTNAME', '(Top level)'))
            ->setShowSearch(true);
        return $tab;
    }