Skip to content

Commit

Permalink
ENH Use class name instead of self
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jun 5, 2024
1 parent 6c1be84 commit abe2359
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/GridFieldAddNewInlineButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private function getRowTemplate(GridField $grid, GridFieldEditableColumns $edita
$field->setName(sprintf(
'%s[%s][{%%=o.num%%}][%s]',
$grid->getName(),
self::POST_KEY,
GridFieldAddNewInlineButton::POST_KEY,
$field->getName()
));

Expand All @@ -145,7 +145,7 @@ private function getRowTemplate(GridField $grid, GridFieldEditableColumns $edita
// Convert GridFieldEditableColumns to the template format
$content = str_replace(
sprintf('[%s][0]', GridFieldEditableColumns::POST_KEY),
sprintf('[%s][{%%=o.num%%}]', self::POST_KEY),
sprintf('[%s][{%%=o.num%%}]', GridFieldAddNewInlineButton::POST_KEY),
$content ?? ''
);
}
Expand Down Expand Up @@ -176,7 +176,9 @@ public function handleSave(GridField $grid, DataObjectInterface $record)
$list = $grid->getList();
$value = $grid->Value();

if (!isset($value[self::POST_KEY]) || !is_array($value[self::POST_KEY])) {
if (!isset($value[GridFieldAddNewInlineButton::POST_KEY])
|| !is_array($value[GridFieldAddNewInlineButton::POST_KEY])
) {
return;
}

Expand All @@ -190,7 +192,7 @@ public function handleSave(GridField $grid, DataObjectInterface $record)
return;
}

foreach ($value[self::POST_KEY] as $fields) {
foreach ($value[GridFieldAddNewInlineButton::POST_KEY] as $fields) {
/** @var DataObject $item */
$item = $class::create();

Expand Down
10 changes: 6 additions & 4 deletions src/GridFieldEditableColumns.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,23 @@ public function handleSave(GridField $grid, DataObjectInterface $record)
$list = $grid->getList();
$value = $grid->Value();

if (!isset($value[self::POST_KEY]) || !is_array($value[self::POST_KEY])) {
if (!isset($value[GridFieldEditableColumns::POST_KEY])
|| !is_array($value[GridFieldEditableColumns::POST_KEY])
) {
return;
}

/** @var GridFieldOrderableRows $sortable */
$sortable = $grid->getConfig()->getComponentByType(GridFieldOrderableRows::class);

// Fetch the items before processing them
$ids = array_keys($value[self::POST_KEY]);
$ids = array_keys($value[GridFieldEditableColumns::POST_KEY]);
if (empty($ids)) {
return;
}
$itemsCollection = ArrayList::create($list->filter('ID', $ids)->toArray());

foreach ($value[self::POST_KEY] as $id => $fields) {
foreach ($value[GridFieldEditableColumns::POST_KEY] as $id => $fields) {
if (!is_numeric($id) || !is_array($fields)) {
continue;
}
Expand Down Expand Up @@ -325,7 +327,7 @@ protected function getFieldName($name, GridField $grid, DataObjectInterface $rec
return sprintf(
'%s[%s][%s][%s]',
$grid->getName(),
self::POST_KEY,
GridFieldEditableColumns::POST_KEY,
$record->ID,
$name
);
Expand Down

0 comments on commit abe2359

Please sign in to comment.