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

Pimcore Editable Numeric uses string values #39

Merged
merged 1 commit into from
Jan 17, 2025

Conversation

mike4git
Copy link
Collaborator

Internally Pimcore uses string in the Numeric Editable - so we have to cast it:

namespace Pimcore\Model\Document\Editable;

use Pimcore\Model;

/**
 * @method \Pimcore\Model\Document\Editable\Dao getDao()
 */
class Numeric extends Model\Document\Editable
{
    /**
     * Contains the current number, or an empty string if not set
     *
     * @internal
     */
    protected ?string $number = null;

    ...

    /**
     * @see EditableInterface::getData
     *
     */
    public function getNumber(): string
    {
        return $this->getData();
    }

    public function frontend()
    {
        return $this->number;
    }

    public function setDataFromResource(mixed $data): static
    {
        $this->number = $data; // <-- here we are running into problems not to cast to string.

        return $this;
    }

    public function setDataFromEditmode(mixed $data): static
    {
        $this->number = (string)$data;

        return $this;
    }

    public function isEmpty(): bool
    {
        if (is_numeric($this->number)) {
            return false;
        }

        return empty($this->number);
    }
}

@mike4git mike4git merged commit 84def2a into main Jan 17, 2025
5 checks passed
@mike4git mike4git deleted the bugfix/use-strings-for-internal-values-of-Numeric branch January 17, 2025 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants