Setup form configuration.

@param  Presenter  $listener
@param  string  $url
@param  Model  $model
@param  array  $attributes

@return $this
193931
public function resource(Presenter $listener = null, $url, Model $model, array $attributes = [])
    {
        $method = 'POST';
        if ($model->exists) {
            $last = last(explode('/', $url));
            if (!is_numeric($last)) {
                $url = "{$url}/{$model->getKey()}";
            }
            $method = 'PUT';
        }
        $attributes['method'] = $method;

        return $this->setup($listener, $url, $model, $attributes);
    }
434770
public function create($listener)
    {
        $model = new Fluent([
            'site' => ['name' => \config('app.name', 'Orchestra Platform')],
        ]);

        $form = $this->presenter->form($model);

        return $listener->createSucceed(\compact('form', 'model'));
    }
1037861
public function open(string $formName, array $attributes = []) : FormInterface
    {
        self::$formName = $formName;
        self::$formHolder[$formName] = $formName;
        self::$formOpen = true;
        $this->form($formName, $attributes);

        return $this;
    }
276960
public static function register($event, $listener) {
            if (!is_subclass_of($listener, Listener::class)) {
                throw new RegisterNonListenerException();
            }

            foreach (self::$listeners as $ev => $registered_listeners) {
                if ($ev & $event && !in_array($listener, $registered_listeners)) {
                    self::$listeners[ $ev ][] = $listener;
                }
            }
        }
650702
public function addEventListener(string $name, callable $listener): self
    {
        if (!isset($this->internalEventListenersData[$name])) {
            $this->internalEventListenersData[$name] = [];
        }
        $this->internalEventListenersData[$name][] = $listener;
        return $this;
    }
1036853
public function addEventListener($events, $listener)
    {
        if (\is_string($listener)) {
            if ($this->initialized) {
                throw new \RuntimeException('Adding lazy-loading listeners after construction is not supported.');
            }

            $hash = '_service_'.$listener;
        } else {
            // Picks the hash code related to that listener
            $hash = spl_object_hash($listener);
        }

        foreach ((array) $events as $event) {
            // Overrides listener if a previous one was associated already
            // Prevents duplicate listeners on same event (same instance only)
            $this->listeners[$event][$hash] = $listener;
        }
    }
163672
public function update(Listener $listener, $id, array $input)
    {
        $model     = with(new Eloquent())->findOrNew($id);
        $memory    = app('antares.memory')->make('ui-components');
        $className = $memory->get($model->name . '.name');
        $component = with(new $className($model->id));
        $rules     = $component->getRules();
        if (empty($rules)) {
            return Response::json([], 200);
        }
        $validation = ValidatorFacade::make($input, $rules);


        if ($validation->fails()) {
            if (app('request')->ajax()) {
                return Response::json($validation->getMessageBag()->getMessages(), 200);
            }
            return $listener->whenValidationFailed($validation->getMessageBag());
        } else {
            $controls      = $component->controls();
            $value         = unserialize($model->value);
            $value['data'] = array_only($input, $controls);
            $model->value  = serialize($value);
            $model->save();
            $memory->getHandler()->forgetCache($this->getResource());
            return Response::json([], 200);
        }
    }
740852
public function edit(SettingUpdateListener $listener)
    {
        // Orchestra settings are stored using Orchestra\Memory, we need to
        // fetch it and convert it to Fluent (to mimick Eloquent properties).
        $memory = $this->memory;

        $eloquent = new Fluent([
            'site_name' => $memory->get('site.name', ''),
            'site_description' => $memory->get('site.description', ''),
            'site_registrable' => ($memory->get('site.registrable', false) ? 'yes' : 'no'),

            'email_driver' => $memory->get('email.driver', ''),
            'email_address' => $memory->get('email.from.address', ''),
            'email_host' => $memory->get('email.host', ''),
            'email_port' => $memory->get('email.port', ''),
            'email_username' => $memory->get('email.username', ''),
            'email_password' => $memory->secureGet('email.password', ''),
            'email_encryption' => $memory->get('email.encryption', ''),
            'email_sendmail' => $memory->get('email.sendmail', ''),
            'email_queue' => ($memory->get('email.queue', false) ? 'yes' : 'no'),
            'email_key' => $memory->secureGet('email.key', ''),
            'email_secret' => $memory->secureGet('email.secret', ''),
            'email_domain' => $memory->get('email.domain', ''),
            'email_region' => $memory->get('email.region', ''),
        ]);

        $form = $this->presenter->form($eloquent);

        Event::dispatch('orchestra.form: settings', [$eloquent, $form]);

        return $listener->showSettingChanger(compact('eloquent', 'form'));
    }
819978
public static function setup($byType, array $attributes)
    {
        if (0 !== preg_match('#^(' . self::$alloweds . '|select|form)$#', $type)) {
            self::$preAttrs[$byType] = $attributes;
        }
    }
150371
public function setEventListeners($listeners)
	{
		$this->ensureEventListeners();
		
		foreach ($listeners as $listener) {
			$this->_eventListeners[Ioc::resolveClassName($listener)] = $listener;
		}
		
		return $this;
	}
601166
public static function createForModel($model, $attributes)
    {
        $model = static::makeForModel($model, $attributes);

        $model->save();

        return $model;
    }
619470
public function build(Presenter $listener, BannedEmail $bannedEmail)
    {
        return $this->form->of('antares.ban_management.banned-emails', function(FormGrid $form) use($listener, $bannedEmail) {
                    $url = $bannedEmail->exists ? route('bannedemails.update', compact('bannedEmail')) : route('bannedemails.store');

                    $attr = ['method' => $bannedEmail->exists ? 'PUT' : 'POST'];

                    $form->setup($listener, $url, $bannedEmail, $attr);
                    $form->name('Banned Emails Form');
                    $form->hidden('id');
                    $form->layout('antares/foundation::components.form');

                    $form->fieldset($bannedEmail->exists ? 'Edit Banned Email' : 'New Banned Email', function (Fieldset $fieldset) use($bannedEmail) {
                        $this->setupFieldset($fieldset, $bannedEmail);
                    });

                    $scenario   = $bannedEmail->exists ? 'update' : 'create';
                    $validation = $this->validation->on($scenario);

                    if (method_exists($validation, 'on' . ucfirst($scenario))) {
                        $validation->{'on' . ucfirst($scenario)}();
                    }

                    $form->ajaxable()->rules($validation->getValidationRules())->phrases($validation->getValidationPhrases());
                });
    }
337968
public static function button($field, $value = null, array $attributes = array())
	{
		return static::$instance->button($field, $value, $attributes);
	}
447422
public function store(Listener $listener, array $input)
    {
        $input['slug'] = $this->generateUniqueSlug($input);
        $validation    = $this->validator->on('create')->with($input);

        if ($validation->fails()) {
            return $listener->storeHasFailedValidation($validation->getMessageBag());
        }

        $content = new Eloquent();
        $content->setAttribute('type', $input['type']);
        $content->setAttribute('user_id', $this->user->id);

        $listener->authorize('create', $content);

        $this->saving($content, $input);

        return $listener->storeHasSucceed($content, $input);
    }
927941
public function resource(Presenter $listener, $url, Model $model, array $attributes = [])
    {
        $method = 'POST';

        if ($model->exists) {
            $url = "{$url}/{$model->getKey()}";
            $method = 'PUT';
        }

        $attributes['method'] = $method;

        return $this->setup($listener, $url, $model, $attributes);
    }
528254
public function create(Listener $listener)
    {
        $eloquent = Foundation::make('orchestra.user');
        $form = $this->presenter->profile($eloquent, 'orchestra::register');

        $form->extend(function ($form) {
            $form->submit = 'orchestra/foundation::title.register';
        });

        $this->fireEvent('form', [$eloquent, $form]);

        return $listener->showProfileCreator(compact('eloquent', 'form'));
    }
1273295
public function AttachObserver($listener)
	{
		if ($listener) {
			$this->_observers[] =& $listener;
			if ($this->_masterAdapter) $this->_masterAdapter->AttachObserver($listener);
		}
		
	}