Simplify boolean attribute handling for Html::input in templates
authorBartosz Dziewoński <matma.rex@gmail.com>
Wed, 16 Oct 2013 16:57:12 +0000 (18:57 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Sun, 20 Oct 2013 19:46:36 +0000 (21:46 +0200)
The Html class supports this handy shorthand.

Change-Id: Ie34790fa650c7ecad02c2d91130bf0db9172ea3f

includes/templates/Usercreate.php
includes/templates/Userlogin.php

index 7a4b9f2..4750af9 100644 (file)
@@ -158,9 +158,10 @@ class UsercreateTemplate extends BaseTemplate {
                                                        'id' => 'wpEmail',
                                                        'tabindex' => '6',
                                                        'size' => '20',
+                                                       'required' => $this->data['emailrequired'],
                                                        'placeholder' => $this->getMsg( $this->data['loggedin'] ?
                                                                'createacct-another-email-ph' : 'createacct-email-ph' )->text()
-                                               ) + ( $this->data['emailrequired'] ? array() : array( 'required' => '' ) ) );
+                                               ) );
                                        ?>
                                <?php } ?>
                        </div>
index f5ae353..5eb6094 100644 (file)
@@ -69,10 +69,6 @@ class UserloginTemplate extends BaseTemplate {
                                </label>
                                <?php
                                $extraAttrs = array();
-                               // Set focus to this field if it's blank.
-                               if ( !$this->data['name'] ) {
-                                       $extraAttrs['autofocus'] = '';
-                               }
                                echo Html::input( 'wpName', $this->data['name'], 'text', array(
                                        'class' => 'loginText',
                                        'id' => 'wpName1',
@@ -80,9 +76,11 @@ class UserloginTemplate extends BaseTemplate {
                                        'size' => '20',
                                        // 'required' is blacklisted for now in Html.php due to browser issues.
                                        // Keeping here in case that changes.
-                                       'required',
+                                       'required' => true,
+                                       // Set focus to this field if it's blank.
+                                       'autofocus' => !$this->data['name'],
                                        'placeholder' => $this->getMsg( 'userlogin-yourname-ph' )->text()
-                               ) + $extraAttrs );
+                               ) );
                                ?>
                        </div>
 
@@ -101,18 +99,15 @@ class UserloginTemplate extends BaseTemplate {
                                        ?>
                                </label>
                                <?php
-                               $extraAttrs = array();
-                               // Set focus to this field if username is filled in.
-                               if ( $this->data['name'] ) {
-                                       $extraAttrs['autofocus'] = '';
-                               }
                                echo Html::input( 'wpPassword', null, 'password', array(
                                        'class' => 'loginPassword',
                                        'id' => 'wpPassword1',
                                        'tabindex' => '2',
                                        'size' => '20',
+                                       // Set focus to this field if username is filled in.
+                                       'autofocus' => (bool)$this->data['name'],
                                        'placeholder' => $this->getMsg( 'userlogin-yourpassword-ph' )->text()
-                               ) + $extraAttrs );
+                               ) );
                                ?>
                        </div>