Samuell1 / revisions-plugin

Revisions allows to extend any model with Revisionable trait with more features and easy to use.
https://octobercms.com/plugin/samuell-revisions
MIT License
9 stars 7 forks source link

Repeaters and Dropdowns throwing errors in revisionhistory field type #32

Closed TimFoerster closed 2 years ago

TimFoerster commented 2 years ago

Version: ocms v3

Cannot use object of type Closure as array
~/plugins/samuell/revisions/formwidgets/RevisionHistory.php line 251
        $optionConfig = $field->config['options'];

        foreach ($oldValue as $item) {
            $old .= isset($optionConfig[$item]) ? $optionConfig[$item] . ' • ' : '';
        }

$field->config['options'] is a closure now. This closure is also present for repeaters. Therefore repeaters also pass this check

            if (isset($field->config['options'])) {
                return $this->getOptionsDiff($field, $oldValue, $newValue);
            }

Which results in method getFIELDNAMEOptions() not exists.

My current hotfixes in RevisionHistory:

    private function getDiff($fieldName, $oldValue, $newValue)
    {
        $fields = $this->parentForm->getFields();

        if (array_key_exists($fieldName, $fields)) {
            ...

            if (isset($field->config['widget']) && $field->config['widget'] === 'repeater') {
                return Diff::htmlDiff(e($oldValue), e($newValue));
            }

            if (isset($field->config['options'])) {
                return $this->getOptionsDiff($field, $oldValue, $newValue);
            }
        }

        return Diff::htmlDiff(e($oldValue), e($newValue));
    }

    private function getOptionsDiff($field, $oldValue, $newValue)
    {
        $optionConfig = $field->config['options']();
        ...
     }

I asked Daftspunky, if the options closure is intended, waiting for reply: https://octobercms.slack.com/archives/C09864473/p1655826963967629

daftspunk commented 2 years ago

Related: https://github.com/octobercms/library/blob/61244ddc52a639f0ac941e06a4dc548261de7b8e/src/Element/Form/FieldDefinition.php#L98-L129

daftspunk commented 2 years ago

More related (this might fix it):

https://github.com/octobercms/library/commit/8c70550038a4f364de85b94afbecdb3caf09282b https://github.com/octobercms/october-private/commit/966b486e41061f21036e31986c0660b22f27fc51

Try Build OCMS v3.0.55+

TimFoerster commented 2 years ago

https://github.com/octobercms/library/commit/8c70550038a4f364de85b94afbecdb3caf09282b https://github.com/octobercms/october-private/commit/966b486e41061f21036e31986c0660b22f27fc51 fixed it