public function getInputFilter()
    {
        if ($this->filter) {
            return $this->filter;
        }

        $specifications = [];

        if ($this->object && $this->object instanceof InputFilterProviderInterface) {
            $specifications = $this->object->getInputFilterSpecification();
        }

        if ($this instanceof InputFilterProviderInterface) {
            $specifications = ArrayUtils::merge($specifications, $this->getInputFilterSpecification());
        }

        $this->addRequiredAttributeToFields($specifications);

        /** @noinspection IsEmptyFunctionUsageInspection */
        if (!empty($specifications) && null === $this->baseFieldset) {
            $formFactory  = $this->getFormFactory();
            $inputFactory = $formFactory->getInputFilterFactory();

            if (!($this->filter instanceof InputFilterInterface)) {
                $this->filter = new InputFilter();
                $this->filter->setFactory($inputFactory);
            }

            foreach ($specifications as $name => $specification) {
                $input = $inputFactory->createInput($specification);

                $this->filter->add($input, $name);
            }
        }

        return parent::getInputFilter();
    }