Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/card improvements #2025

Draft
wants to merge 11 commits into
base: develop
Choose a base branch
from
Draft

Conversation

DarkSide666
Copy link
Member

@DarkSide666 DarkSide666 commented Mar 29, 2023

Multiple improvements for Card and CardDeck - see description of commits.

Also adds additional demo how we can create CardDeck with custom Cards.
image

@@ -147,7 +152,7 @@ public function setModel(Model $model, array $fields = null, array $extra = null
if ($count) {
foreach ($this->model as $m) {
/** @var Card */
$c = $this->cardHolder->add(Factory::factory([$this->card], ['useLabel' => $this->useLabel, 'useTable' => $this->useTable]));
$c = $this->cardHolder->add(Factory::factory((array) $this->card, ['useLabel' => $this->useLabel, 'useTable' => $this->useTable]));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never use (array) cast, change the def. value to be an array seed instead

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will work on that a bit more probably tomorrow. Looks like there are more seed related things to fix in this (and Card) classes for consistency with other views and also to ease extending.

@@ -157,7 +157,7 @@ protected function _setOrAppend($tag, string $value = null, bool $encodeHtml = t
// in this case we don't throw exception if tags don't exist
if (is_array($tag) && $value === null) {
foreach ($tag as $k => $v) {
$this->_setOrAppend($k, $v, $encodeHtml, $append, false);
$this->_setOrAppend($k, (string) $v, $encodeHtml, $append, false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never cast to a string, string type is required

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if you use ->set($model), then it will try to set model id which is integer into template too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see l153/typecasting above, this is already fully handled when set thru model, we cannot do it with array, as php type itself is not enought to determine DBAL/typecasting type, since #1987 we format int using UI persistence config, so (string) will not produce desired output

@@ -64,15 +64,15 @@ public function addFields(Model $model, array $fields, bool $useLabel = false, b
/**
* Add fields label and value to section.
*/
private function addSectionFields(Model $model, array $fields, bool $useLabel = false): void
protected function addSectionFields(Model $model, array $fields, bool $useLabel = false): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Private methods are often added as the API might not be well defined. If private, we do not have to care, but if protected, we need to support the API in a long term. Please confirm you understand this and also there are no simillar private methods in other components.

@DarkSide666 DarkSide666 marked this pull request as draft March 31, 2023 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants