本文整理汇总了PHP中Anomaly\Streams\Platform\Ui\Form\FormBuilder::getFormEntry方法的典型用法代码示例。如果您正苦于以下问题:PHP FormBuilder::getFormEntry方法的具体用法?PHP FormBuilder::getFormEntry怎么用?PHP FormBuilder::getFormEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Anomaly\Streams\Platform\Ui\Form\FormBuilder
的用法示例。
在下文中一共展示了FormBuilder::getFormEntry方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: guess
/**
* Guess the HREF for a button.
*
* @param FormBuilder $builder
*/
public function guess(FormBuilder $builder)
{
$buttons = $builder->getButtons();
$entry = $builder->getFormEntry();
// Nothing to do if empty.
if (!($section = $this->sections->active())) {
return;
}
foreach ($buttons as &$button) {
if (isset($button['attributes']['href'])) {
continue;
}
switch (array_get($button, 'button')) {
case 'cancel':
$button['attributes']['href'] = $section->getHref();
break;
case 'delete':
$button['attributes']['href'] = $section->getHref('delete/' . $entry->getId());
break;
default:
// Determine the HREF based on the button type.
$type = array_get($button, 'button');
if ($type && !str_contains($type, '\\') && !class_exists($type)) {
$button['attributes']['href'] = $section->getHref($type . '/{entry.id}');
}
break;
}
}
$builder->setButtons($buttons);
}
示例2: save
/**
* Save the form.
*
* @param FormBuilder|ConfigurationFormBuilder $builder
* @return bool|mixed
*/
public function save(FormBuilder $builder)
{
$namespace = $builder->getFormEntry() . '::';
/* @var FieldType $field */
foreach ($builder->getFormFields() as $field) {
$this->configurations->set($namespace . $field->getField(), $builder->getScope(), $builder->getFormValue($field->getInputName()));
}
}
示例3: save
/**
* Save the form.
*
* @param FormBuilder $builder
*/
public function save(FormBuilder $builder)
{
$entry = $builder->getFormEntry();
$data = $this->prepareValueData($builder);
if ($entry->getId()) {
$entry->update($data);
} else {
$entry = $entry->create($data);
}
$builder->setFormEntry($entry);
$this->processSelfHandlingFields($builder);
}
示例4: guess
/**
* Guess the field instructions.
*
* @param FormBuilder $builder
*/
public function guess(FormBuilder $builder)
{
$fields = $builder->getFields();
$entry = $builder->getFormEntry();
if (!is_object($entry)) {
return;
}
foreach ($fields as &$field) {
$field['translatable'] = $entry->isTranslatedAttribute($field['field']);
}
$builder->setFields($fields);
}
示例5: guess
/**
* Guess the field unique rule.
*
* @param FormBuilder $builder
*/
public function guess(FormBuilder $builder)
{
$fields = $builder->getFields();
$entry = $builder->getFormEntry();
foreach ($fields as &$field) {
$unique = array_pull($field, 'rules.unique');
/*
* No unique? Continue...
*/
if (!$unique || $unique === false) {
continue;
}
/*
* If unique is a string then
* it's set explicitly.
*/
if ($unique && is_string($unique)) {
$field['rules']['unique'] = 'unique:' . $unique;
continue;
}
/*
* If unique is true then
* automate the rule.
*/
if ($unique && $unique === true) {
$unique = 'unique:' . $entry->getTable() . ',' . $field['field'];
if ($entry instanceof EntryInterface) {
$unique .= ',' . $entry->getId();
}
$field['rules']['unique'] = $unique;
continue;
}
/*
* If unique is an array then use
* the default automation and add to it.
*/
if ($unique && is_array($unique)) {
$unique = 'unique:' . $entry->getTable() . ',' . $field['field'];
if ($entry instanceof EntryInterface) {
$unique .= ',' . $entry->getId();
}
$keys = array_keys($unique);
$values = array_values($unique);
foreach ($keys as $column) {
$unique .= ',' . $column . ',' . $column . ',' . array_shift($values);
}
$field['rules']['unique'] = $unique;
continue;
}
}
$builder->setFields($fields);
}
示例6: populate
/**
* Populate the fields with entry values.
*
* @param FormBuilder $builder
*/
public function populate(FormBuilder $builder)
{
$fields = $builder->getFields();
$entry = $builder->getFormEntry();
foreach ($fields as &$field) {
/*
* If the field is not already set
* then get the value off the entry.
*/
if (!isset($field['value']) && $entry instanceof EloquentModel && $entry->getId()) {
if ($locale = array_get($field, 'locale')) {
$field['value'] = $entry->translateOrDefault($locale)->{$field['field']};
} else {
$field['value'] = $entry->{$field['field']};
}
}
/*
* If the field has a default value
* and the entry does not exist yet
* then use the default value.
*/
if (isset($field['config']['default_value']) && $entry instanceof EloquentModel && !$entry->getId()) {
$field['value'] = $field['config']['default_value'];
}
/*
* If the field has a default value
* and there is no entry then
* use the default value.
*/
if (isset($field['config']['default_value']) && !$entry) {
$field['value'] = $field['config']['default_value'];
}
/*
* If the field is an assignment then
* use it's config for the default value.
*/
if (!isset($field['value']) && $entry instanceof EntryInterface && ($type = $entry->getFieldType($field['field']))) {
$field['value'] = array_get($type->getConfig(), 'default_value');
}
/*
* Lastly if we have flashed data from a front end
* form handler then use that value for the field.
*/
if ($this->session->has($field['prefix'] . $field['field'])) {
$field['value'] = $this->session->pull($field['prefix'] . $field['field']);
}
}
$builder->setFields($fields);
}
示例7: handle
/**
* Handle the form response.
*
* @param FormBuilder $builder
*/
public function handle(FormBuilder $builder)
{
/*
* If the form already has a response
* then we're being overridden. Abort!
*/
if ($builder->getFormResponse()) {
return;
}
$entry = $builder->getFormEntry();
$actions = $builder->getFormActions();
$action = $actions->active();
if ($entry && $entry instanceof Arrayable) {
$entry = $entry->toArray();
}
$redirect = $action->getRedirect();
if ($redirect instanceof RedirectResponse) {
$builder->setFormResponse($redirect);
return;
}
if ($redirect === false) {
return;
}
$redirect = $this->parser->parse($redirect, compact('entry'));
/*
* If the redirect is null then use the current one.
*/
if ($redirect === null) {
$redirect = $this->redirector->back()->getTargetUrl();
}
/*
* If the URL is a closure then call it.
*/
if ($redirect instanceof \Closure) {
$redirect = app()->call($redirect, compact('builder'));
}
/*
* Restore the query string prior if
* we're coming from a table.
*/
if ($query = $this->session->get('table::' . $redirect)) {
$redirect = strpos($redirect, '?') ? $redirect . '&' . $query : $redirect . '?' . $query;
}
$builder->setFormResponse($this->redirector->to($redirect));
}
示例8: guess
/**
* Guess the field required flag.
*
* @param FormBuilder $builder
*/
public function guess(FormBuilder $builder)
{
$fields = $builder->getFields();
$mode = $builder->getFormMode();
$entry = $builder->getFormEntry();
foreach ($fields as &$field) {
// Guess based on the assignment if possible.
if (!isset($field['required']) && $entry instanceof EntryInterface && ($assignment = $entry->getAssignment($field['field']))) {
$field['required'] = array_get($field, 'required', $assignment->isRequired());
}
// Guess based on the form mode if applicable.
if (in_array($required = array_get($field, 'required'), ['create', 'edit'])) {
$field['required'] = $required === $mode;
}
// Guess based on the rules.
if (in_array('required', array_get($field, 'rules', []))) {
$field['required'] = true;
}
}
$builder->setFields($fields);
}
示例9: compile
/**
* Compile rules from form fields.
*
* @param FormBuilder $builder
* @return array
*/
public function compile(FormBuilder $builder)
{
$rules = [];
$entry = $builder->getFormEntry();
$stream = $builder->getFormStream();
$locale = $this->config->get('streams::locales.default');
/* @var FieldType $field */
foreach ($builder->getEnabledFormFields() as $field) {
if ($field->isDisabled()) {
continue;
}
if (in_array($field->getField(), $builder->getSkips())) {
continue;
}
$fieldRules = array_filter(array_unique($field->getRules()));
$fieldRules = $field->extendRules($fieldRules);
if (!$stream instanceof StreamInterface) {
$rules[$field->getInputName()] = implode('|', $fieldRules);
continue;
}
if ($assignment = $stream->getAssignment($field->getField())) {
$type = $assignment->getFieldType();
if ($type->isRequired()) {
$fieldRules[] = 'required';
}
if (!isset($fieldRules['unique']) && $assignment->isUnique() && !$assignment->isTranslatable()) {
$unique = 'unique:' . $stream->getEntryTableName() . ',' . $field->getColumnName();
if ($entry && ($id = $entry->getId())) {
$unique .= ',' . $id;
}
$fieldRules[] = $unique;
}
if ($assignment->isTranslatable() && $field->getLocale() !== $locale) {
$fieldRules = array_diff($fieldRules, ['required']);
}
}
$rules[$field->getInputName()] = implode('|', array_unique($fieldRules));
}
return array_filter($rules);
}
示例10: build
/**
* Build the fields.
*
* @param FormBuilder $builder
*/
public function build(FormBuilder $builder)
{
$skips = $builder->getSkips();
$stream = $builder->getFormStream();
$entry = $builder->getFormEntry();
$this->input->read($builder);
/**
* Convert each field to a field object
* and put to the forms field collection.
*/
foreach ($builder->getFields() as $field) {
// Continue if skipping.
if (in_array($field['field'], $skips)) {
continue;
}
// Continue if not enabled.
if (!array_get($field, 'enabled', true)) {
continue;
}
$builder->addFormField($this->factory->make($field, $stream, $entry));
}
}
示例11: handle
/**
* Handle saving the form data ourselves.
*
* @param FormBuilder $builder
*/
public function handle(FormBuilder $builder)
{
$entry = $builder->getFormEntry();
// See the accessor for how IDs are handled.
$entry->{$this->getField()} = $this->getPostValue();
}
示例12: parse
/**
* Parse the form fields.
*
* @param FormBuilder $builder
*/
public function parse(FormBuilder $builder)
{
$entry = $builder->getFormEntry();
$builder->setFields($this->parser->parse($builder->getFields(), compact('entry')));
}
示例13: evaluate
/**
* Evaluate the form buttons.
*
* @param FormBuilder $builder
*/
public function evaluate(FormBuilder $builder)
{
$entry = $builder->getFormEntry();
$builder->setButtons($this->evaluator->evaluate($builder->getButtons(), compact('builder', 'entry')));
}
示例14: handle
/**
* Handle the command.
*/
public function handle(MessageBag $messages, Translator $translator)
{
// If we can't save or there are errors then skip it.
if ($this->builder->hasFormErrors() || !$this->builder->canSave()) {
return;
}
// If there is no model and there isn't anything specific to say, skip it.
if (!$this->builder->getFormEntry() && !$this->builder->getFormOption('success_message')) {
return;
}
$mode = $this->builder->getFormMode();
// False means no message is desired.
if ($this->builder->getFormOption('success_message') === false) {
return;
}
$entry = $this->builder->getFormEntry();
$stream = $this->builder->getFormStream();
$parameters = ['title' => is_object($entry) ? $entry->getTitle() : null, 'name' => is_object($stream) ? $stream->getName() : null];
// If the name doesn't exist we need to be clever.
if (str_contains($parameters['name'], '::') && !$translator->has($parameters['name']) && $stream) {
$parameters['name'] = ucfirst(str_singular(str_replace('_', ' ', $stream->getSlug())));
} elseif ($parameters['name']) {
$parameters['name'] = str_singular(trans($parameters['name']));
} else {
$parameters['name'] = trans('streams::entry.name');
}
/**
* Set the default success message.
*/
if ($this->builder->getFormOption('success_message') === null) {
$this->builder->setFormOption('success_message', trans('streams::message.' . $mode . '_success', $parameters));
}
$messages->{$this->builder->getFormOption('success_message_type', 'success')}($this->builder->getFormOption('success_message'));
}