Edit Method for Fieldhandler Method

@return  $this
@since   1.0.0
@throws  \CommonApi\Exception\InvalidArgumentException
187691
protected function editFieldhandlerMethod()
    {
        if (in_array($this->method, array('validate', 'sanitize', 'format'))) {
            return $this;
        }

        throw new InvalidArgumentException(
            get_class($this)
            . ' passed in invalid Fieldhandler method '
            . $this->method
            . ' in FieldhandlerUsageTrait::editFieldhandlerMethod.'
        );
    }
1292448
protected function getFieldsetHelper()
    {
    	if ($this->fieldsetHelper) {
    	    return $this->fieldsetHelper;
    	}

    	if (method_exists($this->view, 'plugin')) {
    	    $this->fieldsetHelper = $this->view->plugin($this->defaultFieldsetHelper);
    	}

    	if (!$this->fieldsetHelper instanceof AbstractHelper) {
    	    // @todo Ideally the helper should implement an interface.
    	    throw InvalidHelperException::invalidHelperInstance($this->fieldsetHelper);
    	}

    	return $this->fieldsetHelper;
    }
311692
public function adapt()
    {
        if (method_exists($this, $this->adaptMethodName) && $this->data) {
            call_user_func([$this, $this->adaptMethodName]);
        }

        return $this;
    }
145850
public function beforeDetach()
    {
        $handler = $this->get('handler');
        if (class_exists($handler)) {
            $handler = new $handler();

            return $handler->beforeDetach($this);
        }
    }
1263436
protected function validateEditField()
    {
        $this->setSubmitted('field');
        $this->setSubmitted('update', $this->data_field);

        $this->validateComponent('field');

        return !$this->hasErrors();
    }
821355
public function forceEditable()
    {
        array_set($this->attributes, 'force_editable', true);
        array_set($this->attributes, 'force_displayable', true);
        return $this;
    }
8034
public function editAction()
    {
        /* @var $user \Auth\Entity\User */
        $user = $this->userRepository->find($this->params('id'), \Doctrine\ODM\MongoDB\LockMode::NONE, null, ['allowDeactivated' => true]);
        
        // check if user is not found
        if (!$user) {
            return $this->notFoundAction();
        }
        
        $params = $this->params();
        $forms = $this->formManager;
        /* @var $infoContainer \Auth\Form\UserProfileContainer */
        $infoContainer = $forms->get('Auth/UserProfileContainer');
        $infoContainer->setEntity($user);
        $statusContainer = $forms->get('Auth/UserStatusContainer');
        $statusContainer->setEntity($user);
        
        // set selected user to image strategy
        $imageStrategy = $infoContainer->getForm('info.image')
            ->getHydrator()
            ->getStrategy('image');
		$fileEntity = $imageStrategy->getFileEntity();
		$fileEntity->setUser($user);
		$imageStrategy->setFileEntity($fileEntity);
        
        if ($this->request->isPost()) {
            $formName = $params->fromQuery('form');
            $container = $formName === 'status' ? $statusContainer : $infoContainer;
            $form = $container->getForm($formName);
        
            if ($form) {
                $postData  = $form->getOption('use_post_array') ? $params->fromPost() : [];
                $filesData = $form->getOption('use_files_array') ? $params->fromFiles() : [];
                $form->setData(array_merge($postData, $filesData));
        
                if (!$form->isValid()) {
                    return new JsonModel(
                        array(
                            'valid' => false,
                            'errors' => $form->getMessages(),
                        )
                    );
                }
                
                $this->userRepository->store($user);
        
                if ('file-uri' === $params->fromPost('return')) {
                    $content = $form->getHydrator()->getLastUploadedFile()->getUri();
                } else {
                    if ($form instanceof SummaryFormInterface) {
                        $form->setRenderMode(SummaryFormInterface::RENDER_SUMMARY);
                        $viewHelper = 'summaryForm';
                    } else {
                        $viewHelper = 'form';
                    }
                    $content = $this->viewHelper->get($viewHelper)->__invoke($form);
                }
        
                return new JsonModel(
                    array(
                        'valid' => $form->isValid(),
                        'content' => $content,
                    )
                );
            }
        }
        
        return [
            'infoContainer' => $infoContainer,
            'statusContainer' => $statusContainer
        ];
    }
700320
public function editAction()
    {
        $form = $this->getEditForm();
        $entity = $form->getObject();
        if ($this->getRequest()->isPost()) {
            $data = $this->getRequest()->getPost()->toArray();
            $entityManager = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
            $hydrator = new DoctrineHydrator($entityManager);
            $hydrator->hydrate($data, $entity);

            if ($form->isValid()) {
                $objectManager = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
                $objectManager->persist($entity);
                $objectManager->flush();
                $controller = explode('/', $this->getRequest()->getUri()->getPath())[2];
                if (!$this->getRequest()->isXmlHttpRequest()) {
                    return $this->redirect()->toRoute(null, ['controller' => $controller]);
                }
                return;
            } else {
                $this->getResponse()->setStatusCode(400);
            }
        }
        $viewModel = $this->getViewModel();
        $viewModel->setTerminal($this->getRequest()->isXmlHttpRequest());

        return $viewModel->setVariables(['form' => $form]);
    }
1167061
protected function processField($method, array $field = array(), array $options = array())
    {
        $this->field  = $field;
        $this->method = strtolower($method);

        $this->editFieldhandlerMethod();

        foreach (array('name', 'value', 'type') as $key) {
            $this->editFieldhandlerAttribute($key);
        }

        $fieldhandler_results = $this->executeConstraint($options);

        $this->processConstraintResults($fieldhandler_results);

        return $this->field_value;
    }
792442
public function edit()
    {
        if (!userHasPermission('admin:invoice:customer:edit')) {
            unauthorised();
        }

        $oCustomerModel = Factory::model('Customer', 'nails/module-invoice');
        $oUri           = Factory::service('Uri');

        $itemId             = (int) $oUri->segment(5);
        $this->data['item'] = $oCustomerModel->getById(
            $itemId,
            ['expand' => $oCustomerModel::EXPAND_ALL]
        );

        if (empty($this->data['item'])) {
            show404();
        }

        // --------------------------------------------------------------------------

        $oInput = Factory::service('Input');
        if ($oInput->post()) {

            try {

                $this->formValidation();

                if (!$oCustomerModel->update($itemId, $this->prepPostData())) {
                    throw new NailsException('Failed to update item. ' . $oCustomerModel->lastError(), 1);
                }

                $oSession = Factory::service('Session', 'nails/module-auth');
                $oSession->setFlashData('success', 'Item updated successfully.');
                redirect('admin/invoice/customer');

            } catch (\Exception $e) {
                $this->data['error'] = $e->getMessage();
            }
        }

        // --------------------------------------------------------------------------

        $this->data['page']->title = 'Edit customer';
        Helper::loadView('edit');
    }
869755
public function editAction()
    {
        $default    = false;
        $params     = $this->params();
        $request    = $this->getRequest();
        $locator    = $this->getServiceLocator();
        $model      = $locator->get( 'Grid\Core\Model\SubDomain\Model' );
        /* @var $form \Zend\Form\Form */
        $form       = $locator->get( 'Form' )
                              ->create( 'Grid\Core\SubDomain' );

        if ( ( $id = $params->fromRoute( 'id' ) ) )
        {
            $subDomain = $model->find( $id );

            if ( empty( $subDomain ) )
            {
                $this->getResponse()
                     ->setStatusCode( 404 );

                return;
            }

            if ( empty( $subDomain->subdomain ) )
            {
                $default = true;

                $form->get( 'subdomain' )
                     ->setRequired( false );
            }
        }
        else
        {
            if ( ! $this->getServiceLocator()
                        ->get( 'Grid\User\Model\Permissions\Model' )
                        ->isAllowed( 'subDomain', 'create' ) )
            {
                $this->getResponse()
                     ->setStatusCode( 403 );

                return;
            }

            $subDomain = $model->create( array() );
        }

        /* @var $form \Zend\Form\Form */
        $form->setHydrator( $model->getMapper() )
             ->bind( $subDomain );

        if ( $request->isPost() )
        {
            $form->setData( $request->getPost() );

            if ( $form->isValid() && $subDomain->save() )
            {
                if ( $default && ! empty( $subDomain->subdomain ) )
                {
                    $newDefault = $model->create( array(
                        'subdomain'         => '',
                        'locale'            => $subDomain->locale,
                        'defaultLayoutId'   => $subDomain->defaultLayoutId,
                        'defaultContentId'  => $subDomain->defaultContentId,
                    ) );

                    $newDefault->save();
                }

                $this->messenger()
                     ->add( 'subDomain.form.success',
                            'subDomain', Message::LEVEL_INFO );

                return $this->redirect()
                            ->toRoute( 'Grid\Core\SubDomain\List', array(
                                'locale' => (string) $this->locale(),
                            ) );
            }
            else
            {
                $this->messenger()
                     ->add( 'subDomain.form.failed',
                            'subDomain', Message::LEVEL_ERROR );
            }
        }

        $form->setCancel(
            $this->url()
                 ->fromRoute( 'Grid\Core\SubDomain\List', array(
                        'locale' => (string) $this->locale(),
                    ) )
        );

        return array(
            'form'      => $form,
            'subDomain' => $subDomain,
        );
    }
1092928
public function addCallableHandle()
    {
        if ($this->handler) {
            throw new AlreadyBuildedException('The handler already builded.');
        }

        $loader = new CallableLoader();
        $resolver = new CallableResolver();

        $this->addCallableResolver($resolver);
        $this->addActionLoader($loader);

        return $loader;
    }
910958
public function editor($fields)
    {
        $this->setTemplate($this->config->get('datatables-html.editor', 'datatables::editor'));

        $editor = $this->newEditor($fields);

        $this->editors[] = $editor;

        return $this;
    }
319264
protected function updateTitle() {
		$title = $this->getTitle();
		if ( $title !== null ) {
			// Only if this is an AccessKeyedElement
			if ( method_exists( $this, 'formatTitleWithAccessKey' ) ) {
				$title = $this->formatTitleWithAccessKey( $title );
			}
			$this->titled->setAttributes( [ 'title' => $title ] );
		} else {
			$this->titled->removeAttributes( [ 'title' ] );
		}
		return $this;
	}
1217804
public function bulkEditForm()
    {
        $crumbs = $this->Breadcrumbs();
        if ($crumbs && $crumbs->count() >= 2) {
            $one_level_up = $crumbs->offsetGet($crumbs->count() - 2);
        }

        $actions = new FieldList();

        $actions->push(
            FormAction::create('doSave', _t('GRIDFIELD_BULKMANAGER_EDIT_HANDLER.SAVE_BTN_LABEL', 'Save all'))
                ->setAttribute('id', 'bulkEditingSaveBtn')
                ->addExtraClass('btn btn-success')
                ->setAttribute('data-icon', 'accept')
                ->setUseButtonTag(true)
        );

        $actions->push(
            FormAction::create('Cancel', _t('GRIDFIELD_BULKMANAGER_EDIT_HANDLER.CANCEL_BTN_LABEL', 'Cancel'))
                ->setAttribute('id', 'bulkEditingUpdateCancelBtn')
                ->addExtraClass('btn btn-danger cms-panel-link')
                ->setAttribute('data-icon', 'decline')
                ->setAttribute('href', $one_level_up->Link)
                ->setUseButtonTag(true)
                ->setAttribute('src', '')//changes type to image so isn't hooked by default actions handlers
        );

        $recordList = $this->getRecordIDList();
        $recordsFieldList = new FieldList();
        $config = $this->component->getConfig();

        $editingCount = count($recordList);
        $modelClass = $this->gridField->getModelClass();
        $singleton = singleton($modelClass);
        $titleModelClass = (($editingCount > 1) ? $singleton->i18n_plural_name() : $singleton->i18n_singular_name());

        //some cosmetics
        $headerText = _t(
            'GRIDFIELD_BULKMANAGER_EDIT_HANDLER.HEADER_TEXT',
            'Editing {count} {class}',
            array(
                'count' => $editingCount,
                'class' => $titleModelClass,
            )
        );
        $header = LiteralField::create(
            'bulkEditHeader',
            '<h1 id="bulkEditHeader">'.$headerText.'</h1>'
        );
        $recordsFieldList->push($header);

        $toggle = LiteralField::create(
            'bulkEditToggle',
            '<span id="bulkEditToggle">' . _t('GRIDFIELD_BULKMANAGER_EDIT_HANDLER.TOGGLE_ALL_LINK', 'Show/Hide all') . '</span>'
        );
        $recordsFieldList->push($toggle);

        //fetch fields for each record and push to fieldList
        foreach ($recordList as $id) {
            $record = DataObject::get_by_id($modelClass, $id);
            $recordEditingFields = $this->getRecordEditingFields($record);

            $toggleField = ToggleCompositeField::create(
                'RecordFields_' . $id,
                $record->getTitle(),
                $recordEditingFields
            )
            ->setHeadingLevel(4)
            ->setAttribute('data-id', $id)
            ->addExtraClass('bulkEditingFieldHolder');

            $recordsFieldList->push($toggleField);
        }

        $bulkEditForm = Form::create(
            $this,
            'recordEditForm', //recordEditForm name is here to trick SS to pass all subform request to recordEditForm()
            $recordsFieldList,
            $actions
        );

        if ($crumbs && $crumbs->count() >= 2) {
            $bulkEditForm->Backlink = $one_level_up->Link;
        }

        //override form action URL back to bulkEditForm
        //and add record ids GET var
        $bulkEditForm->setAttribute(
            'action',
            $this->Link('bulkEditForm?records[]='.implode('&', $recordList))
        );

        return $bulkEditForm;
    }
994992
public static function method()
    {
        $partialArgs = func_get_args();
        if (count($partialArgs) < 1) {
            throw new \InvalidArgumentException();
        }
        $name = array_shift($partialArgs);
        return function () use ($name, $partialArgs) {
            $args = func_get_args();
            if (count($args) < 1) {
                throw new \InvalidArgumentException();
            }
            $obj = array_shift($args);
            return call_user_func_array([&$obj, $name], array_merge($partialArgs, $args));
        };
    }
1133648
protected function registerHandler()
	{
		$this->app['exception'] = $this->app->share(function($app)
		{
			return new Handler($app, $app['exception.plain'], $app['exception.debug']);
		});
	}