<commit_before><?php

namespace CyberDuck\SEO\Admin;

use Page;
use CyberDuck\SEO\Forms\GridField\PublishPageRequest;
use SilverStripe\Admin\ModelAdmin;
use SilverStripe\Control\Controller;
use SilverStripe\Core\Config\Config;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\GridField\GridFieldDetailForm;
use SilverStripe\Forms\GridField\GridFieldAddNewButton;
use SilverStripe\Forms\GridField\GridFieldDeleteAction;
use SilverStripe\Forms\GridField\GridFieldEditButton;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\ArrayList;
use SilverStripe\Versioned\Versioned;

/**
 * SEOAdmin
 *
 * Class which creates the SEO CMS section for SEO management across pages
 *
 * @package silverstripe-seo
 * @license MIT License https://github.com/cyber-duck/silverstripe-seo/blob/master/LICENSE
 * @author  <<EMAIL>>
 **/
class SEOAdmin extends ModelAdmin
{
    /**
     * The SEO admin area is for managing page SEO, not for page creation. Some grid
     * field components are removed from the SEO admin by default.
     * 
     * @since version 1.0.0
     *
     * @param mixed $id
     * @param mixed $fields
     *
     * @return FieldList
     **/
    public function getEditForm($id = null, $fields = null)
    {
        $form = parent::getEditForm($id, $fields);

        $class = new $this->modelClass;
        if($class instanceof Page) {
            $form
                ->Fields()
                ->fieldByName($this->sanitiseClassName($this->modelClass))
                ->getConfig()
                ->getComponentByType(GridFieldDetailForm::class)
                ->setItemRequestClass(PublishPageRequest::class);
        }
        $grid = $form->Fields()->fieldByName($this->sanitiseClassName($this->modelClass));
        $grid->getConfig()->removeComponentsByType(GridFieldAddNewButton::class);
        $grid->getConfig()->removeComponentsByType(GridFieldDeleteAction::class);
        $grid->getConfig()->removeComponentsByType(GridFieldEditButton::class);

        $list = $this
            ->getList()
            ->filter($this->getFilters())
            ->sort('Priority', 'DESC');

        $grid->setList($list);

        $this->extend('updateEditForm',  $grid);
        
        return $form;
    }

    /**
     * Get list of CMS grid pages
     *
     * @since version 1.0.0
     *
     * @return object
     **/<commit_msg>add fix for seo admin grid model class after filter applied<commit_after><?php

namespace CyberDuck\SEO\Admin;

use Page;
use CyberDuck\SEO\Forms\GridField\PublishPageRequest;
use SilverStripe\Admin\ModelAdmin;
use SilverStripe\Control\Controller;
use SilverStripe\Core\Config\Config;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\GridField\GridFieldDetailForm;
use SilverStripe\Forms\GridField\GridFieldAddNewButton;
use SilverStripe\Forms\GridField\GridFieldDeleteAction;
use SilverStripe\Forms\GridField\GridFieldEditButton;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\ArrayList;
use SilverStripe\Versioned\Versioned;

/**
 * SEOAdmin
 *
 * Class which creates the SEO CMS section for SEO management across pages
 *
 * @package silverstripe-seo
 * @license MIT License https://github.com/cyber-duck/silverstripe-seo/blob/master/LICENSE
 * @author  <<EMAIL>>
 **/
class SEOAdmin extends ModelAdmin
{
    /**
     * The SEO admin area is for managing page SEO, not for page creation. Some grid
     * field components are removed from the SEO admin by default.
     * 
     * @since version 1.0.0
     *
     * @param mixed $id
     * @param mixed $fields
     *
     * @return FieldList
     **/
    public function getEditForm($id = null, $fields = null)
    {
        $form = parent::getEditForm($id, $fields);

        $class = new $this->modelClass;
        if($class instanceof Page) {
            $form
                ->Fields()
                ->fieldByName($this->sanitiseClassName($this->modelClass))
                ->getConfig()
                ->getComponentByType(GridFieldDetailForm::class)
                ->setItemRequestClass(PublishPageRequest::class);
        }
        $grid = $form->Fields()->fieldByName($this->sanitiseClassName($this->modelClass));
        $grid->getConfig()->removeComponentsByType(GridFieldAddNewButton::class);
        $grid->getConfig()->removeComponentsByType(GridFieldDeleteAction::class);
        $grid->getConfig()->removeComponentsByType(GridFieldEditButton::class);

        $list = $this
            ->getList()
            ->filter($this->getFilters())
            ->sort('Priority', 'DESC');

        $grid->setList($list);
        $grid->setModelClass($class->ClassName);

        $this->extend('updateEditForm',  $grid);
        
        return $form;
    }

    /**
     * Get list of CMS grid pages
     *
     * @since version 1.0.0
     *
     * @return object
     **/
{'fraction_non_alphanumeric': 0.12263955177422702, 'fraction_numerical': 0.0024901431832330357, 'mean_word_length': 2.899676375404531, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 57, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1965724', 'n_tokens_mistral': 1431, 'n_tokens_neox': 1404, 'n_words': 287}