wanze / FieldtypeSecureFile

A ProcessWire Fieldtype storing files in a customized location, outside the web root.
GNU General Public License v2.0
8 stars 1 forks source link

Fatal Error on newer versions of ProcessWire #6

Open cb2004 opened 3 years ago

cb2004 commented 3 years ago

Not sure when this issue crept in, I am guessing when the file/image fields were refactored:

Fatal Error: Uncaught Error: Call to a member function getOptions() on null in site/modules/FieldtypeSecureFile/FieldtypeSecureFile.module:205

cb2004 commented 3 years ago

There is also an error on line 211 once commenting out line 205

Fatal Error: Uncaught Error: Attempt to assign property "notes" on null in site/modules/FieldtypeSecureFile/FieldtypeSecureFile.module:211

craigrodway commented 3 years ago

If you move that section into a newly-created ___getConfigAdvancedInputfields function, it seems to resolve this error. Perhaps the inputfieldClass was moved to the 'advanced' function at some point?

    public function ___getConfigInputfields(Field $field)
    {
        $inputfields = parent::___getConfigInputfields($field);
        // rest of function, $fStorage = ...
    }

    /**
     * Field advanced config
     *
     */
    public function ___getConfigAdvancedInputfields(Field $field)
    {
        $inputfields = parent::___getConfigAdvancedInputfields($field);

        // Only allow InputfieldFile as Inputfield
        $fInputfield = $inputfields->get('inputfieldClass');
        $options = $fInputfield->getOptions();
        foreach ($options as $option => $title) {
            if (!in_array($option, static::$allowedInputFields)) {
                $fInputfield->removeOption($option);
            }
        }
        $fInputfield->notes = $this->_('Currently, InputfieldFile is the only supported Inputfield for secure files');

        return $inputfields;
    }
cb2004 commented 3 years ago

That is a confirmed fix, although I wont close the issue until @wanze takes a look.

wanze commented 3 years ago

Thanks @cb2004 and @craigrodway I am a bit disconnected from ProcessWire at the moment, would it be possible to send a pull request? 😊 Not sure how we should implement this without breaking the module for older versions of ProcessWire though.

Cheers