<commit_before><?php

namespace Dynamic\FlexSlider\Model;

use SilverStripe\AssetAdmin\Forms\UploadField;
use SilverStripe\Assets\Image;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;

/**
 * Class SlideImage
 * @package Dynamic\FlexSlider\Model
 * @property string $Name
 * @property string $Headline
 * @property string $Description
 * @property int $SortOrder
 * @property int $ImageID
 * @property int $PageID
 * @property int $PageLinkID
 */
class SlideImage extends DataObject implements PermissionProvider
{
    /**
     * @var string
     */
    private static $singular_name = 'Slide';

    /**
     * @var string
     */
    private static $plural_name = 'Slides';

    /**
     * @var array
     */
    private static $db = array(
        'Name' => 'Varchar(255)',
        'Headline' => 'Varchar(255)',
        'Description' => 'Text',
        'SortOrder' => 'Int',
    );

    /**
     * @var array
     */
    private static $has_one = array(
        'Image' => Image::class,
        'Page' => \Page::class,
        'PageLink' => SiteTree::class,
    );

    /**
     * @var array
     */
    private static $owns = array(
        'Image'
    );

    /**
     * @var string
     */
    private static $table_name = 'SlideImage';

    /**
     * @var string
     */
    private static $default_sort = 'SortOrder';

    /**
     * Adds Publish button to SlideImage record
    *
    * @var bool
    */
    private static $versioned_gridfield_extensions = true;

    /**
     * @var array
     */
    private static $summary_fields = array(
        'Image.CMSThumbnail' => 'Image',
        'Name' => 'Name',
    );

    /**
     * @var array
     */
    private static $searchable_fields = array(
        'Name',
        'Headline',
        'Description',
    );

    /**
     * @var int
     */
    private static $image_size_limit = 512000;

    /**
     * @return \SilverStripe\Forms\FieldList
     */
    public function getCMSFields()
    {
        $fields = parent::getCMSFields();

        $fields->removeByName([
            'ShowSlide',
            'SortOrder',
            'PageID',
            'Image',
        ]);

        // Name
        $fields->dataFieldByName('Name')
            ->setTitle(
                _t(__CLASS__ . '.NAME', 'Name')
            )
            ->setDescription(
                _t(__CLASS__ . '.INTERNAL_USE', 'for internal reference only')
            );

        // Headline
        $fields->dataFieldByName('Headline')
            ->setTitle(
                _t(__CLASS__ . '.HEADLINE', 'Headline')
            )
            ->setDescription(
                _t(__CLASS__ . '.USED_IN_TEMPLATE', 'optional, used in template')
            );

        // Description
        $fields->dataFieldByName('Description')
            ->setTitle(
                _t(__CLASS__ . '.DESCRIPTION', 'Description')
            )
            ->setDescription(
                _t(__CLASS__ . '.USED_IN_TEMPLATE', 'optional, used in template')
            );

        // Page link
        $fields->dataFieldByName('PageLinkID')
            ->setTitle(
                _t(__CLASS__ . '.PAGE_LINK', "Choose a page to link to:")
            );

        // Image
        $image = UploadField::create(
            'Image',
            _t(__CLASS__ . '.IMAGE', 'Image')
        )->setFolderName('Uploads/SlideImages');

        $image->getValidator()->setAllowedExtensions(['jpg', 'jpeg', 'png', 'gif']);

        $fields->insertAfter($image, 'Description');

        $this->extend('updateSlideImageFields', $fields);

        return $fields;<commit_msg>refactor - SlideImage - move CMS fields to onBeforeUpdateCMSFields() (#141)<commit_after><?php

namespace Dynamic\FlexSlider\Model;

use SilverStripe\AssetAdmin\Forms\UploadField;
use SilverStripe\Assets\Image;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;

/**
 * Class SlideImage
 * @package Dynamic\FlexSlider\Model
 * @property string $Name
 * @property string $Headline
 * @property string $Description
 * @property int $SortOrder
 * @property int $ImageID
 * @property int $PageID
 * @property int $PageLinkID
 */
class SlideImage extends DataObject implements PermissionProvider
{
    /**
     * @var string
     */
    private static $singular_name = 'Slide';

    /**
     * @var string
     */
    private static $plural_name = 'Slides';

    /**
     * @var array
     */
    private static $db = array(
        'Name' => 'Varchar(255)',
        'Headline' => 'Varchar(255)',
        'Description' => 'Text',
        'SortOrder' => 'Int',
    );

    /**
     * @var array
     */
    private static $has_one = array(
        'Image' => Image::class,
        'Page' => \Page::class,
        'PageLink' => SiteTree::class,
    );

    /**
     * @var array
     */
    private static $owns = array(
        'Image'
    );

    /**
     * @var string
     */
    private static $table_name = 'SlideImage';

    /**
     * @var string
     */
    private static $default_sort = 'SortOrder';

    /**
     * Adds Publish button to SlideImage record
    *
    * @var bool
    */
    private static $versioned_gridfield_extensions = true;

    /**
     * @var array
     */
    private static $summary_fields = array(
        'Image.CMSThumbnail' => 'Image',
        'Name' => 'Name',
    );

    /**
     * @var array
     */
    private static $searchable_fields = array(
        'Name',
        'Headline',
        'Description',
    );

    /**
     * @var int
     */
    private static $image_size_limit = 512000;

    /**
     * @return \SilverStripe\Forms\FieldList
     */
    public function getCMSFields()
    {
        $this->beforeUpdateCMSFields(function ($fields) {
            $fields->removeByName([
                'ShowSlide',
                'SortOrder',
                'PageID',
                'Image',
            ]);

            // Name
            $fields->dataFieldByName('Name')
                ->setTitle(
                    _t(__CLASS__ . '.NAME', 'Name')
                )
                ->setDescription(
                    _t(__CLASS__ . '.INTERNAL_USE', 'for internal reference only')
                );

            // Headline
            $fields->dataFieldByName('Headline')
                ->setTitle(
                    _t(__CLASS__ . '.HEADLINE', 'Headline')
                )
                ->setDescription(
                    _t(__CLASS__ . '.USED_IN_TEMPLATE', 'optional, used in template')
                );

            // Description
            $fields->dataFieldByName('Description')
                ->setTitle(
                    _t(__CLASS__ . '.DESCRIPTION', 'Description')
                )
                ->setDescription(
                    _t(__CLASS__ . '.USED_IN_TEMPLATE', 'optional, used in template')
                );

            // Page link
            $fields->dataFieldByName('PageLinkID')
                ->setTitle(
                    _t(__CLASS__ . '.PAGE_LINK', "Choose a page to link to:")
                );

            // Image
            $image = UploadField::create(
                'Image',
                _t(__CLASS__ . '.IMAGE', 'Image')
            )->setFolderName('Uploads/SlideImages');

            $image->getValidator()->setAllowedExtensions(['jpg', 'jpeg', 'png', 'gif']);

            $fields->insertAfter($image, 'Description');
        });

        $fields = parent::getCMSFields();

        $this->extend('updateSlideImageFields', $fields);

        return $fields;
{'fraction_non_alphanumeric': 0.13715775749674056, 'fraction_numerical': 0.0035202086049543678, 'mean_word_length': 1.752421959095802, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 56, 'https://': 0, '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': '7347427', 'n_tokens_mistral': 2270, 'n_tokens_neox': 2159, 'n_words': 450}