From abe2359f7890f4d923a2b75d7bd7afc8d026f84b Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 5 Jun 2024 17:29:25 +1200 Subject: [PATCH] ENH Use class name instead of self --- src/GridFieldAddNewInlineButton.php | 10 ++++++---- src/GridFieldEditableColumns.php | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/GridFieldAddNewInlineButton.php b/src/GridFieldAddNewInlineButton.php index 0d888b4..4983d2c 100755 --- a/src/GridFieldAddNewInlineButton.php +++ b/src/GridFieldAddNewInlineButton.php @@ -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() )); @@ -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 ?? '' ); } @@ -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; } @@ -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(); diff --git a/src/GridFieldEditableColumns.php b/src/GridFieldEditableColumns.php index d8cd7fd..b787ea4 100644 --- a/src/GridFieldEditableColumns.php +++ b/src/GridFieldEditableColumns.php @@ -121,7 +121,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[GridFieldEditableColumns::POST_KEY]) + || !is_array($value[GridFieldEditableColumns::POST_KEY]) + ) { return; } @@ -129,13 +131,13 @@ public function handleSave(GridField $grid, DataObjectInterface $record) $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; } @@ -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 );