Skip to content

Commit

Permalink
REFACTOR RecipePage - Inline Editing for directions, ingredients (#45)
Browse files Browse the repository at this point in the history
* REFACTOR RecipePage - Inline Editing for directions, ingredients

phpstan updates

* remove GridFieldEditButton from Directions

* phpstan
  • Loading branch information
jsirish authored Jan 14, 2025
1 parent 4080aa2 commit 5a49f01
Showing 1 changed file with 44 additions and 4 deletions.
48 changes: 44 additions & 4 deletions src/Page/RecipePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@
use Dynamic\RecipeBook\Model\RecipeDirection;
use Dynamic\RecipeBook\Model\RecipeIngredient;
use SilverStripe\AssetAdmin\Forms\UploadField;
use Dynamic\RecipeBook\Page\RecipeCategoryPage;
use SilverStripe\Forms\GridField\GridFieldConfig;
use SilverStripe\Versioned\GridFieldArchiveAction;
use SilverStripe\Forms\GridField\GridFieldButtonRow;
use SilverStripe\Forms\GridField\GridFieldEditButton;
use Symbiote\GridFieldExtensions\GridFieldTitleHeader;
use SilverStripe\Forms\GridField\GridFieldDeleteAction;
use SilverStripe\Forms\GridField\GridFieldToolbarHeader;
use Symbiote\GridFieldExtensions\GridFieldOrderableRows;
use Symbiote\GridFieldExtensions\GridFieldEditableColumns;
use Symbiote\GridFieldExtensions\GridFieldAddNewInlineButton;
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor;
use Symbiote\GridFieldExtensions\GridFieldAddExistingSearchButton;
use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter;
Expand All @@ -39,21 +47,25 @@ class RecipePage extends \Page
{
/**
* @var string
* @config
*/
private static string $singular_name = 'Recipe';

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

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

/**
* @var array
* @config
*/
private static array $db = [
'Servings' => 'Varchar(20)',
Expand All @@ -64,13 +76,15 @@ class RecipePage extends \Page

/**
* @var array
* @config
*/
private static $has_one = [
'Image' => Image::class,
];

/**
* @var array
* @config
*/
private static array $has_many = [
'Ingredients' => RecipeIngredient::class,
Expand All @@ -79,13 +93,15 @@ class RecipePage extends \Page

/**
* @var array
* @config
*/
private static array $many_many = [
'Categories' => RecipeCategoryPage::class,
];

/**
* @var array
* @config
*/
private static array $many_many_extraFields = [
'Categories' => [
Expand All @@ -95,6 +111,7 @@ class RecipePage extends \Page

/**
* @var string[]
* @config
*/
private static $owns = [
'Image',
Expand All @@ -112,6 +129,7 @@ class RecipePage extends \Page

/**
* @var array
* @config
*/
private static array $defaults = [
'ShowInMenu' => false,
Expand All @@ -120,16 +138,19 @@ class RecipePage extends \Page

/**
* @var bool
* @config
*/
private static bool $can_be_root = false;

/**
* @var bool
* @config
*/
private static bool $show_in_sitetree = false;

/**
* @var array
* @config
*/
private static array $allowed_children = [];

Expand Down Expand Up @@ -178,7 +199,7 @@ public function getCMSFields(): FieldList
'Ingredients',
'Ingredients',
$this->Ingredients(),
$ingredientsConfig = GridFieldConfig_RelationEditor::create()
$ingredientsConfig = GridFieldConfig::create()
)
);

Expand All @@ -188,7 +209,7 @@ public function getCMSFields(): FieldList
'Directions',
'Directions',
$this->Directions(),
$directionsConfig = GridFieldConfig_RelationEditor::create()
$directionsConfig = GridFieldConfig::create()
)
);

Expand All @@ -209,11 +230,30 @@ public function getCMSFields(): FieldList

$ingredientsConfig
->addComponent(new GridFieldOrderableRows('Sort'))
->removeComponentsByType(GridFieldAddExistingAutocompleter::class);
->removeComponentsByType(GridFieldAddExistingAutocompleter::class)
->addComponent(GridFieldButtonRow::create('before'))
->addComponent(GridFieldToolbarHeader::create())
->addComponent(GridFieldTitleHeader::create())
->addComponent(GridFieldEditableColumns::create())
->addComponent(GridFieldDeleteAction::create())
->addComponent(GridFieldAddNewInlineButton::create());

$directionsConfig
->addComponent(new GridFieldOrderableRows('Sort'))
->removeComponentsByType(GridFieldAddExistingAutocompleter::class);
->removeComponentsByType(GridFieldAddExistingAutocompleter::class)
->addComponent(GridFieldButtonRow::create('before'))
->addComponent(GridFieldToolbarHeader::create())
->addComponent(GridFieldTitleHeader::create())
->addComponent(GridFieldEditableColumns::create())
->addComponent(GridFieldDeleteAction::create())
->addComponent(GridFieldAddNewInlineButton::create());

$directionsConfig->getComponentByType(GridFieldEditableColumns::class)->setDisplayFields(array(
'Title' => array(
'title' => 'Title',
'field' => TextField::class
),
));

$catConfig
->removeComponentsByType([
Expand Down

0 comments on commit 5a49f01

Please sign in to comment.