private function patchStateOperation(Page $page, array &$operations)
    {
        $stateOp = null;
        $isHiddenOp = null;
        foreach ($operations as $key => $operation) {
            $op = [
                'key' => $key,
                'op' => $operation
            ];
            if ('/state' === $operation['path']) {
                $stateOp = $op;
            } elseif ('/is_hidden' === $operation['path']) {
                $isHiddenOp = $op;
            }
        }

        if ($page->isOnline(true)) {
            $this->granted('PUBLISH', $page);
        }

        if (null !== $stateOp) {
            unset($operations[$stateOp['key']]);
            $states = explode('_', $stateOp['op']['value']);
            if (in_array($state = (int) array_shift($states), Page::$STATES)) {
                $page->setState($state | ($page->getState() & Page::STATE_HIDDEN ? Page::STATE_HIDDEN : 0));
            }

            if ($code = (int) array_shift($states)) {
                $workflowState = $this->getApplication()->getEntityManager()
                    ->getRepository('BackBee\Workflow\State')
                    ->findOneBy([
                        '_code'   => $code,
                        '_layout' => $page->getLayout(),
                    ])
                ;

                if (null !== $workflowState) {
                    $page->setWorkflowState($workflowState);
                }
            }
        }

        if (null !== $isHiddenOp) {
            unset($operations[$isHiddenOp['key']]);

            $isHidden = (boolean) $isHiddenOp['op']['value'];
            if ($isHidden && !($page->getState() & Page::STATE_HIDDEN)) {
                $page->setState($page->getState() | Page::STATE_HIDDEN);
            } elseif (!$isHidden && ($page->getState() & Page::STATE_HIDDEN)) {
                $page->setState($page->getState() ^ Page::STATE_HIDDEN);
            }
        }
    }