Как мне отредактировать many_many_extraFields в SilverStripe 4? - PullRequest
1 голос
/ 19 июня 2019

У меня есть дополнительное поле Data, добавленное к отношению многие ко многим, и я понятия не имею, как его редактировать.

Функция

private static $belongs_many_many = [
        'Model' => Model::class
    ];

Модель

private static $many_many = [
        'Features' => Feature::class,
    ];

private static $many_many_extraFields = [
    'Features' => [
        'SortOrder' => 'Int',
        'Data' => 'Varchar'
    ]
];



-- / --

$features = Feature::get();
$searchFeaturesButton = new GridFieldAddExistingSearchButton();
$searchFeaturesButton->setSearchList($features);
$featureConfig = GridFieldConfig_RelationEditor::create();
$featureConfig->removeComponentsByType([GridFieldAddExistingAutocompleter::class, GridFieldEditButton::class, GridFieldAddNewButton::class]);
$featureConfig->addComponent(new GridFieldOrderableRows());
$featureConfig->addComponent($searchFeaturesButton);
$featureGrid = GridField::create('Features', 'Features', $this->Features(), $featureConfig);
$field->addFieldToTab('Root.Main', $featureGrid);

-- / --


Как просмотреть Data как столбец в моем GridField и сделать его редактируемым?

Сортировка работает нормально, так как она управляетсяGridfieldOrderableRows()

1 Ответ

1 голос
/ 21 июня 2019

В SilverStripe 3 и 4 мы можем использовать модуль SilverStripe GridField Extensions GridFieldEditableColumns для редактирования many_many_extraFields данных.

Вот пример того, как это сделать:

// Features field existing search button
$featuresGridFieldSearchButton = new GridFieldAddExistingSearchButton();
$featuresGridFieldSearchButton->setSearchList(Feature::get());

// Features field editable columns
$featuresGridFieldEditableColumns = new GridFieldEditableColumns();
$featuresGridFieldEditableColumns->setDisplayFields([
    'Title' => [
        'title' => 'Title',
        'field' => ReadonlyField::class,
    ],
    'Data' => [
        'title' => 'Data',
        'field' => TextField::class,
    ],
]);

// Features field config including base GridFieldConfig_RelationEditor components, custom search button, editable columns and orderable rows
$featuresGridFieldConfig = GridFieldConfig::create();
$featuresGridFieldConfig->addComponent(new GridFieldButtonRow('before'));
$featuresGridFieldConfig->addComponent($featuresGridFieldSearchButton);
$featuresGridFieldConfig->addComponent(new GridFieldToolbarHeader());
$featuresGridFieldConfig->addComponent(new GridFieldTitleHeader());
$featuresGridFieldConfig->addComponent($featuresGridFieldEditableColumns);
$featuresGridFieldConfig->addComponent(new GridFieldDeleteAction(true));
$featuresGridFieldConfig->addComponent(new GridFieldOrderableRows());
$featuresGridFieldConfig->addComponent(new GridFieldPageCount('toolbar-header-right'));
$featuresGridFieldConfig->addComponent(new GridFieldPaginator());
$featuresGridFieldConfig->addComponent(new GridFieldDetailForm());

$featuresGridField = GridField::create(
    'Features',
    'Features',
    $this->Features(),
    $featuresGridFieldConfig
);

$fields->addFieldToTab('Root.Features', $featuresGridField);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...