当前位置: 首页>>代码示例>>PHP>>正文


PHP FormBuilder::getFormMode方法代码示例

本文整理汇总了PHP中Anomaly\Streams\Platform\Ui\Form\FormBuilder::getFormMode方法的典型用法代码示例。如果您正苦于以下问题:PHP FormBuilder::getFormMode方法的具体用法?PHP FormBuilder::getFormMode怎么用?PHP FormBuilder::getFormMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Anomaly\Streams\Platform\Ui\Form\FormBuilder的用法示例。


在下文中一共展示了FormBuilder::getFormMode方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: handle

 /**
  * Set the form model object from the builder's model.
  *
  * @param SetDefaultParameters $command
  */
 public function handle()
 {
     /*
      * Set the form mode according
      * to the builder's entry.
      */
     if (!$this->builder->getFormMode()) {
         $this->builder->setFormMode($this->builder->getFormEntryId() || $this->builder->getEntry() ? 'edit' : 'create');
     }
     /*
      * Next we'll loop each property and look for a handler.
      */
     $reflection = new \ReflectionClass($this->builder);
     /* @var \ReflectionProperty $property */
     foreach ($reflection->getProperties(\ReflectionProperty::IS_PROTECTED) as $property) {
         if (in_array($property->getName(), $this->skips)) {
             continue;
         }
         /*
          * If there is no getter then skip it.
          */
         if (!method_exists($this->builder, $method = 'get' . ucfirst($property->getName()))) {
             continue;
         }
         /*
          * If the parameter already
          * has a value then skip it.
          */
         if ($this->builder->{$method}()) {
             continue;
         }
         /*
          * Check if we can transform the
          * builder property into a handler.
          * If it exists, then go ahead and use it.
          */
         $handler = str_replace('FormBuilder', 'Form' . ucfirst($property->getName()), get_class($this->builder));
         if (class_exists($handler)) {
             /*
              * Make sure the handler is
              * formatted properly.
              */
             if (!str_contains($handler, '@')) {
                 $handler .= '@handle';
             }
             $this->builder->{'set' . ucfirst($property->getName())}($handler);
             continue;
         }
         /*
          * If the handler does not exist and
          * we have a default handler, use it.
          */
         if ($default = array_get($this->defaults, $property->getName())) {
             $this->builder->{'set' . ucfirst($property->getName())}($default);
         }
     }
 }
开发者ID:huglester,项目名称:streams-platform,代码行数:62,代码来源:SetDefaultParameters.php

示例2: handle

 /**
  * Handle the command.
  *
  * @param Container            $container
  * @param ViewTemplate         $template
  * @param BreadcrumbCollection $breadcrumbs
  */
 public function handle(Container $container, ViewTemplate $template, BreadcrumbCollection $breadcrumbs)
 {
     $form = $this->builder->getForm();
     if ($handler = $form->getOption('data')) {
         $container->call($handler, compact('form'));
     }
     if ($layout = $form->getOption('layout_view')) {
         $template->put('layout', $layout);
     }
     if ($title = $form->getOption('title')) {
         $template->put('title', $title);
     }
     // Move this to options so we can read it.
     $this->builder->setFormOption('read_only', $this->builder->isReadOnly());
     $form->addData('form', $form);
     if ($breadcrumb = $form->getOption('breadcrumb', 'streams::form.mode.' . $this->builder->getFormMode())) {
         $breadcrumbs->put($breadcrumb, '#');
     }
 }
开发者ID:huglester,项目名称:streams-platform,代码行数:26,代码来源:LoadForm.php

示例3: defaults

 /**
  * Default the form actions when none are defined.
  *
  * @param FormBuilder $builder
  */
 public function defaults(FormBuilder $builder)
 {
     if ($builder->getActions() === []) {
         if ($builder->getFormMode() == 'create') {
             $builder->setActions(['save', 'save_create']);
         } else {
             $builder->setActions(['update', 'save_exit']);
         }
     }
 }
开发者ID:huglester,项目名称:streams-platform,代码行数:15,代码来源:ActionDefaults.php

示例4: guess

 /**
  * Guess the field instructions.
  *
  * @param FormBuilder $builder
  */
 public function guess(FormBuilder $builder)
 {
     $fields = $builder->getFields();
     $mode = $builder->getFormMode();
     foreach ($fields as &$field) {
         // Guess based on the form mode if applicable.
         if (in_array((string) ($disabled = array_get($field, 'disabled', null)), ['create', 'edit'])) {
             $field['disabled'] = $disabled === $mode;
         }
     }
     $builder->setFields($fields);
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:17,代码来源:DisabledGuesser.php

示例5: guess

 /**
  * Guess the action's enabled parameter.
  *
  * @param FormBuilder $builder
  */
 public function guess(FormBuilder $builder)
 {
     $actions = $builder->getActions();
     $mode = $builder->getFormMode();
     foreach ($actions as &$action) {
         if (isset($action['enabled']) && is_bool($action['enabled'])) {
             return;
         }
         if (isset($action['enabled']) && is_string($action['enabled'])) {
             $action['enabled'] = $mode === $action['enabled'];
         }
     }
     $builder->setActions($actions);
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:19,代码来源:EnabledGuesser.php

示例6: guess

 /**
  * Guess the HREF for a button.
  *
  * @param FormBuilder $builder
  */
 public function guess(FormBuilder $builder)
 {
     $buttons = $builder->getButtons();
     $mode = $builder->getFormMode();
     foreach ($buttons as &$button) {
         if (!isset($button['enabled'])) {
             continue;
         }
         if (is_bool($button['enabled'])) {
             continue;
         }
         $button['enabled'] = $mode === $button['enabled'];
     }
     $builder->setButtons($buttons);
 }
开发者ID:huglester,项目名称:streams-platform,代码行数:20,代码来源:EnabledGuesser.php

示例7: guess

 /**
  * Guess the HREF for a button.
  *
  * @param FormBuilder $builder
  */
 public function guess(FormBuilder $builder)
 {
     $buttons = $builder->getButtons();
     $mode = $builder->getFormMode();
     foreach ($buttons as &$button) {
         if (isset($button['enabled']) && is_bool($button['enabled'])) {
             return;
         }
         switch (array_get($button, 'button')) {
             case 'delete':
                 $button['enabled'] = $mode === 'edit';
                 break;
         }
     }
     $builder->setButtons($buttons);
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:21,代码来源:EnabledGuesser.php

示例8: guess

 /**
  * Guess some some form action parameters.
  *
  * @param FormBuilder $builder
  */
 public function guess(FormBuilder $builder)
 {
     $actions = $builder->getActions();
     $section = $this->sections->active();
     reset($actions);
     $first = key($actions);
     foreach ($actions as $key => &$action) {
         // If we already have an HREF then skip it.
         if (isset($action['redirect'])) {
             continue;
         }
         if ($key == $first && ($redirect = $builder->getOption('redirect'))) {
             $action['redirect'] = $redirect;
             continue;
         }
         // Determine the HREF based on the action type.
         switch (array_get($action, 'action')) {
             case 'save':
             case 'submit':
             case 'save_exit':
                 $action['redirect'] = $section ? $section->getHref() : $this->request->fullUrl();
                 break;
             case 'update':
             case 'save_edit':
             case 'save_continue':
                 $action['redirect'] = function () use($section, $builder) {
                     if ($section && $builder->getFormMode() == 'create') {
                         return $section->getHref('edit/' . $builder->getContextualId());
                     }
                     return $this->request->fullUrl();
                 };
                 break;
             case 'save_edit_next':
                 $ids = array_filter(explode(',', $builder->getRequestValue('edit_next')));
                 if (!$ids) {
                     $action['redirect'] = $section ? $section->getHref() : $this->request->fullUrl();
                 } elseif (count($ids) == 1) {
                     $action['redirect'] = $section ? $section->getHref('edit/' . array_shift($ids)) : $this->request->fullUrl();
                 } else {
                     $action['redirect'] = $section ? $section->getHref('edit/' . array_shift($ids) . '?' . $builder->getOption('prefix') . 'edit_next=' . implode(',', $ids)) : $this->request->fullUrl();
                 }
                 break;
         }
     }
     $builder->setActions($actions);
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:51,代码来源:RedirectGuesser.php

示例9: 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);
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:26,代码来源:RequiredGuesser.php

示例10: guess

 /**
  * Guess some some form action parameters.
  *
  * @param FormBuilder $builder
  */
 public function guess(FormBuilder $builder)
 {
     $actions = $builder->getActions();
     $section = $this->sections->active();
     reset($actions);
     $first = key($actions);
     foreach ($actions as $key => &$action) {
         /*
          * If we already have an
          * HREF then skip it.
          */
         if (isset($action['redirect'])) {
             continue;
         }
         /*
          * If this is the first action and the
          * form builder has a redirect option
          * then use it for the action redirect.
          */
         if ($key == $first && ($redirect = $builder->getOption('redirect'))) {
             $action['redirect'] = $redirect;
             continue;
         }
         /*
          * If we're not in admin then just assume we
          * need to head back to the form. No redirect
          * will redirect back in this case.
          */
         if ($this->request->segment(1) !== 'admin') {
             continue;
         }
         // Determine the HREF based on the action type.
         switch (array_get($action, 'action')) {
             case 'save':
             case 'submit':
             case 'save_exit':
                 $action['redirect'] = $section ? $section->getHref() : $this->request->fullUrl();
                 break;
             case 'save_create':
                 $action['redirect'] = $this->request->fullUrl();
                 break;
             case 'update':
             case 'save_edit':
             case 'save_continue':
                 $action['redirect'] = function () use($section, $builder) {
                     if ($section && $builder->getFormMode() == 'create') {
                         return $section->getHref('edit/' . $builder->getContextualId());
                     }
                     return $this->request->fullUrl();
                 };
                 break;
             case 'save_edit_next':
                 $ids = array_filter(explode(',', $builder->getRequestValue('edit_next')));
                 if (!$ids) {
                     $action['redirect'] = $section ? $section->getHref() : $this->request->fullUrl();
                 } elseif (count($ids) == 1) {
                     $action['redirect'] = $section ? $section->getHref('edit/' . array_shift($ids)) : $this->request->fullUrl();
                 } else {
                     $action['redirect'] = $section ? $section->getHref('edit/' . array_shift($ids) . '?' . $builder->getOption('prefix') . 'edit_next=' . implode(',', $ids)) : $this->request->fullUrl();
                 }
                 break;
         }
     }
     $builder->setActions($actions);
 }
开发者ID:huglester,项目名称:streams-platform,代码行数:70,代码来源:RedirectGuesser.php

示例11: 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'));
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:37,代码来源:SetSuccessMessage.php


注:本文中的Anomaly\Streams\Platform\Ui\Form\FormBuilder::getFormMode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。