Skip to content

Commit

Permalink
REFACTOR RecipePage - Inline Editing for directions, ingredients
Browse files Browse the repository at this point in the history
phpstan updates
  • Loading branch information
jsirish committed Dec 2, 2024
1 parent 554b52d commit 3bf5c13
Showing 1 changed file with 55 additions and 16 deletions.
71 changes: 55 additions & 16 deletions src/Page/RecipePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,32 @@

namespace Dynamic\RecipeBook\Page;

use Dynamic\RecipeBook\Model\RecipeDirection;
use Dynamic\RecipeBook\Model\RecipeIngredient;
use SilverStripe\Forms\FieldGroup;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter;
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor;
use SilverStripe\Forms\GridField\GridFieldEditButton;
use SilverStripe\Forms\ReadonlyField;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\HasManyList;
use SilverStripe\Forms\FieldGroup;
use SilverStripe\ORM\ManyManyList;
use SilverStripe\Forms\ReadonlyField;
use SilverStripe\Forms\GridField\GridField;
use Dynamic\RecipeBook\Model\RecipeDirection;
use Dynamic\RecipeBook\Model\RecipeIngredient;
use Dynamic\RecipeBook\Page\RecipeCategoryPage;
use SilverStripe\Forms\GridField\GridFieldConfig;
use SilverStripe\Versioned\GridFieldArchiveAction;
use Symbiote\GridFieldExtensions\GridFieldAddExistingSearchButton;
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;

/**
* Class RecipePage
Expand All @@ -37,21 +45,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 @@ -62,6 +74,7 @@ class RecipePage extends \Page

/**
* @var array
* @config
*/
private static array $has_many = [
'Ingredients' => RecipeIngredient::class,
Expand All @@ -70,13 +83,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 @@ -86,6 +101,7 @@ class RecipePage extends \Page

/**
* @var array
* @config
*/
private static array $defaults = [
'ShowInMenu' => false,
Expand All @@ -94,16 +110,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 @@ -141,7 +160,7 @@ public function getCMSFields(): FieldList
'Ingredients',
'Ingredients',
$this->Ingredients(),
$ingredientsConfig = GridFieldConfig_RelationEditor::create()
$ingredientsConfig = GridFieldConfig::create()
)
);

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

Expand All @@ -172,11 +191,31 @@ 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())
->addComponent(GridFieldEditButton::create());

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

$catConfig
->removeComponentsByType([
Expand Down

0 comments on commit 3bf5c13

Please sign in to comment.