If you try and setup a register without having created a store, it shows a blank store option and the form can't be completed. We need to update the form to explain and link to the store creation.

Comments

smccabe created an issue. See original summary.

shabana.navas’s picture

Assigned: Unassigned » shabana.navas
shabana.navas’s picture

Status: Active » Needs review
StatusFileSize
new1.6 KB
alexpott’s picture

Status: Needs review » Needs work
  1. +++ b/src/Form/RegisterForm.php
    @@ -14,6 +16,18 @@ class RegisterForm extends ContentEntityForm {
       public function form(array $form, FormStateInterface $form_state) {
    +    // Skip building the form if there are no available stores.
    +    $stores = Store::loadMultiple();
    

    I think in an ideal world we'd do this a bit differently. I think we should deny access to register creation if there are no stores. And on admin/commerce/config/pos/registers if there are no stores then we should have help text to explain that in order to add a register you need to add a store. However that's quite a bit of work for not a huge amount of gain. We could just use drupal_set_message() and do throw new AccessDeniedHttpException(); as a quick work around. That would also remove the need for overriding the actions method.

  2. +++ b/src/Form/RegisterForm.php
    @@ -14,6 +16,18 @@ class RegisterForm extends ContentEntityForm {
    +      $link = Link::createFromRoute('Add a new store.', 'entity.commerce_store.add_page');
    +      $form['warning'] = [
    +        '#markup' => $this->t("Registers can't be created until a store has been added. @link", ['@link' => $link->toString()]),
    +      ];
    

    See #2923176-5: No Register helper text for a comment about the translatability of something like this.

shabana.navas’s picture

Assigned: shabana.navas » Unassigned
sorabh.v6’s picture

Assigned: Unassigned » sorabh.v6
sorabh.v6’s picture

Assigned: sorabh.v6 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new1.44 KB

Rerolled patch, as it wasn't applying on my local. RegisterForm.php had different code.

Please review, changes made as suggested in #4.

jnrfred’s picture

StatusFileSize
new13.36 KB

Patch tested and works as described above. But do we need to show access denied? Because it sounds like a permission issue.

smccabe’s picture

Status: Needs review » Needs work

Agree with Fred, the not authorized makes this weird, you are authorized, you just don't meet the prerequisites to do anything yet. I think we're using permissions as a proxy for just not showing a link here, which isn't really good either. We WANT the user to attempt to setup a register and then see that they need to create a store, it leads them to the right place, if we hide an option, it only makes it more difficult for them.

Alex, in the reference issue, you recommend a set message instead of a form warning, any reason one is better than the other?

rakesh.gectcr’s picture

Assigning myself.

rakesh.gectcr’s picture

Assigned: Unassigned » rakesh.gectcr
rakesh.gectcr’s picture

Status: Needs work » Needs review
StatusFileSize
new1.4 KB
new512 bytes

I am totally agreeing with #8 and #9, So removing throw new AccessDeniedHttpException(); .

IMHO, drupal_set_message() automatically themed. Alex also mentions that in comments on the other issue.

subhojit777’s picture

Assigned: rakesh.gectcr » subhojit777

Reviewing the patch.

subhojit777’s picture

Status: Needs review » Needs work
  1. +++ b/src/Form/RegisterForm.php
    @@ -14,11 +17,30 @@ class RegisterForm extends ContentEntityForm {
    +    if ($form_state->get('no_stores')) {
    

    This is not working.

  2. +++ b/src/Form/RegisterForm.php
    @@ -14,11 +17,30 @@ class RegisterForm extends ContentEntityForm {
    +    $actions = parent::actions($form, $form_state);
    

    Better do this return parent::actions(), instead of creating new variable.

Found these problems. I am going to work on them.

subhojit777’s picture

+++ b/src/Form/RegisterForm.php
@@ -2,8 +2,11 @@
+use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;

Unnecessary use statement also found.

subhojit777’s picture

Assigned: subhojit777 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new1.06 KB
new1.63 KB
smccabe’s picture

StatusFileSize
new1.42 KB

Added one more change, as with Alex's access deny removed, we still see a form we can't use, but can fill out. I added a quick return so as to not show the form if we have no stores, and only the message.

subhojit777’s picture

Status: Needs review » Needs work
  1. +++ b/src/Form/RegisterForm.php
    @@ -14,11 +16,34 @@ class RegisterForm extends ContentEntityForm {
    +    $form = parent::form($form, $form_state);
    

    We can do return parent::form() here.

  2. +++ b/src/Form/RegisterForm.php
    @@ -14,11 +16,34 @@ class RegisterForm extends ContentEntityForm {
    +    ¶
    

    Whitespace.

sorabh.v6’s picture

Assigned: Unassigned » sorabh.v6
sorabh.v6’s picture

Assigned: sorabh.v6 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new305 bytes
new1.39 KB

Hi,

Patch updated as per #18. Please review.

smccabe’s picture

StatusFileSize
new5.2 KB

Added a test as well as some code styling cleanup so this would pass. It fixes a few small styling issues unrelated to this patch, but I wanted 100% passing and I figured it wasn't worth an extra issue since they're very minor.

Just gonna wait for tests to pass Drupal CI and then I'm gonna merge in, thanks all.

smccabe’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.