Problem/Motivation
Follow-up to : #2889425: Porting Uc wishlist module to Drupal 8 | Phase 1 & #2880447: Porting Uc wishlist module to Drupal 8 | Phase 2
Proposed resolution
- uc_wishlist.info.yml:
configure: admin/store/settings/wishlist
Configure link should point to a route name. - uc_wishlist.install: Remove uc_wishlist_update_7001
/** * Replaced the anonymous configuration settings with 'create wish lists' * permissions. */ function uc_wishlist_update_7001() { $allow_anonymous = \Drupal::config()->get('uc_wishlist_allow_anonymous', FALSE); if ($allow_anonymous) { user_role_change_permissions(DRUPAL_ANONYMOUS_RID, ['create wish lists' => TRUE]); } variable_del('uc_wishlist_allow_anonymous'); }
- uc_wishlist.links.task.yml:
uc_wishlist.tab_1: route_name: uc_wishlist.wishlist.email_form title: Email base_route: uc_wishlist.wishlist.email_form weight:
Remove the weight key and rename the menu task key to uc_wishlist.email
- uc_wishlist.module uc_wishlist_form_alter:
$database = new DBQuery(\Drupal::database());
Convert the DBQuery class from a helper class to a service and inject the database connection service into it and call the service using \Drupal::service("servicename"); - uc_wishlist.module uc_wishlist_form_alter:
uc_order_load($_SESSION['cart_order']);
This is not a function in ubercart 8.x use Order::load instead - uc_wishlist.module uc_wishlist_remove_from_wishlist_submit:
drupal_set_message(t('<b>@product_title</b> was removed from <a href="@url">your wish list</a>.',['@product_title'=>$productTitle,'@url'=>\Drupal\Core\Url::fromRoute('uc_wishlist.wishlist')->toString()]));
Remove the html from the translate method and add a use statement of the Url class at the top and use the Url class instead of whole namespace. - uc_wishlist.module uc_wishlist_create_wishlist:
drupal_set_message(t('You must be logged in to create a wish list. Please <a href="@login_url">login</a> or <a href="@register_url">register</a>.', array( '@login_url' => Drupal\Core\Url::fromRoute('user.login'), '@register_url' => Drupal\Core\Url::fromRoute('user.register') )));
Add a use statement of the Url class at the top and use the Url class instead of whole namespace.
- uc_wishlist.module uc_wishlist_create_wishlist:
$config = \Drupal::config('uc_wishlist');
Which configuration is it returning? It should be \Drupal::config('uc_wishlist.settings') - uc_wishlist.module uc_wishlist_add_item:
if (!$wid) { drupal_set_message($this->t('Could not create wish list. Adding item failed.'), 'error'); return FALSE; }
What's $this here?
- uc_wishlist.module uc_product_update_wishlist_item:
uc_wishlist_remove_item($wpid);
Where's this uc_wishlist_remove_item function defined. - uc_wishlist.module uc_wishlist_views_api: hook_views_api has been removed in drupal 8 see https://www.drupal.org/node/1875596
- uc_wishlist.permissions.yml:
administer wish lists: title: 'administer wish lists' description: 'Allows editing or deletion of any wish list.' create wish lists: title: 'create wish lists' description: 'Allow creation and editing of own wish list.'
Update the description of the administer wish lists that reflect what this permissions does.
- uc_wishlist.permission.yml: Why this file is required?
- uc_wishlist.routing.yml:
uc_wishlist.settings: path: '/admin/store/config/wishlist' defaults: _form: '\Drupal\uc_wishlist\Form\UcWishlistConfigForm' _title: 'Wish list settings' requirements: _permission: 'Administer wish list settings.' options: _admin_route: TRUE
Wrong permission name. It should be the key of the permission
- uc_wishlist.rules.inc:
function uc_wishlist_condition_product_wishlist($order, $settings) { return uc_wishlist_order_wishlist($order); }
Where uc_wishlist_order_wishlist is defined?
- src/UcWishlistListBuilder.php: Where this class has been used?
- src/Entity/UcWishlist.php: Where this class has been used?
- src/Database/DBQuery.php: Convert this class to a service. See how to create services https://www.drupal.org/docs/8/api/services-and-dependency-injection/serv...
- src/Form/UCWishlistAdminDeleteForm.php: Add docblock to these properties
protected $user; protected $wishlistId;
- src/Form/UCWishlistAdminDeleteForm.php:
public function buildForm(array $form, FormStateInterface $form_state, $wishlist = NULL) { $this->node = $node; $this->featureId = $fid; $this->feature = uc_product_feature_load($pfid); $wishlist = uc_wishlist_load($wishlist); $form['wishlist'] = [ '#type' => 'value', '#value' => $wishlist, ]; return parent::buildForm($form, $form_state); }
From where the $node and $fid are coming?
- src/Form/UCWishlistAdminDeleteForm.php:
public function submitForm(array &$form, FormStateInterface $form_state) { $values = $form_state->getValues(); $database = new DBQuery(\Drupal::database()); $database->deleteWishlist($values['wishlist']->wid); drupal_set_message(t('@title has been deleted.', ['@title' => str_replace('.','',$values['wishlist']->title)])); $form_state->setRedirect('uc_wishlist.admin_wishlist'); }
Use $this->t instead of t function directly
- src/Form/WishlistEmailForm.php:
$emails = explode(',', $form_state->getValue['recipients']);
getValue does not have any property at formstate class.
- src/Form/WishlistEmailForm.php:
$form_state->setError('emails', $this->t('%email is not a valid email address', ['%email' => $email]));
does emails element exist on the form? - src/Form/WishlistSearchForm.php: Remove unused use statements from the class.
- src/Form/WishlistSearchForm.php: Remove unused commented code.
//protected $database; /** *public function __construct() { $this->db = new Database\DBQuery(\Drupal::database()); } * */
- src/Form/WishlistSearchForm.php: buildForm:
$form['search']['keywords'] = [ '#type' => 'textfield', '#title' => t('Search keywords'), '#description' => t('Enter the keywords to use to search wish list titles and addresses.'), '#default_value' => $keywords, ];
From where this $keywords variable is coming?
- src/Form/WishlistSearchForm.php: buildForm:
foreach ($result as $wishlist) { $links[] = [ 'title' => Xss::filter($wishlist->title, []), 'href' => 'wishlist/' . $wishlist->wid, ]; }
From where did $result variable is coming?
- src/Form/WishlistSearchForm.php: submitForm: Formstate class doesn't have getValue property. It's getValue method. Referring code:
if (empty($form_state->getValue['keywords'])) {
- src/Form/WishlistViewForm.php: Remove the commented code and unused code from the class.
- src/Form/WishlistViewForm.php: buildForm:
$form['#attached']['library'][] = 'uc_wishlist/ideal_image_slider';
Where's this library is defined? - src/Form/WishlistViewForm.php: Undefined class Node in the file. Add a use statement for the Node class.
- src/Form/WishlistViewForm.php: submitForm:
$this->database->remove_item($wpid);
Where remove_item is defined? - src/Form/WishlistViewForm.php: submitForm:
$database = new \Drupal\uc_wishlist\Database\DBQuery(\Drupal::database());
Add a Use statement of the DBQuery class and use the DBQuery instead of whole namespace
Remaining tasks
Provide the patch to fix them.
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#50 | interdiff-2904915-49-50.txt | 50.12 KB | naveenvalecha |
#50 | 2904915-50.patch | 79.3 KB | naveenvalecha |
Comments
Comment #2
naveenvalechaHere's the round 1 of review of the 8.x-1.x branch
configure: admin/store/settings/wishlist
Configure link should point to a route name.Remove the weight key and rename the menu task key to uc_wishlist.email
$database = new DBQuery(\Drupal::database());
Convert the DBQuery class from a helper class to a service and inject the database connection service into it and call the service using \Drupal::service("servicename");uc_order_load($_SESSION['cart_order']);
This is not a function in ubercart 8.x use Order::load insteaddrupal_set_message(t('<b>@product_title</b> was removed from <a href="@url">your wish list</a>.',['@product_title'=>$productTitle,'@url'=>\Drupal\Core\Url::fromRoute('uc_wishlist.wishlist')->toString()]));
Remove the html from the translate method and add a use statement of the Url class at the top and use the Url class instead of whole namespace.Add a use statement of the Url class at the top and use the Url class instead of whole namespace.
$config = \Drupal::config('uc_wishlist');
Which configuration is it returning? It should be \Drupal::config('uc_wishlist.settings')What's $this here?
uc_wishlist_remove_item($wpid);
Where's this uc_wishlist_remove_item function defined.Update the description of the administer wish lists that reflect what this permissions does.
Wrong permission name. It should be the key of the permission
Where uc_wishlist_order_wishlist is defined?
From where the $node and $fid are coming?
Use $this->t instead of t function directly
getValue does not have any property at formstate class.
$form_state->setError('emails', $this->t('%email is not a valid email address', ['%email' => $email]));
does emails element exist on the form?From where this $keywords variable is coming?
From where did $result variable is coming?
if (empty($form_state->getValue['keywords'])) {
$form['#attached']['library'][] = 'uc_wishlist/ideal_image_slider';
Where's this library is defined?$this->database->remove_item($wpid);
Where remove_item is defined?$database = new \Drupal\uc_wishlist\Database\DBQuery(\Drupal::database());
Add a Use statement of the DBQuery class and use the DBQuery instead of whole namespaceComment #3
naveenvalechaBumping this to major because the module is throwing errors and not usable.
Comment #4
chiranjeeb2410 CreditAttribution: chiranjeeb2410 at Google Summer of Code commented@naveenvalecha,
Fresh patch addresses majority of the issues previously listed. Created services for dbquery helper class, however working on injecting it in .module file. Also, issue for viewing wishlist after adding products has been resolved.
Working on the remaining ones.
Please review.
Comment #6
chiranjeeb2410 CreditAttribution: chiranjeeb2410 at Google Summer of Code commentedComment #8
chiranjeeb2410 CreditAttribution: chiranjeeb2410 at Google Summer of Code commentedComment #10
naveenvalecha@chiranjeeb2410,
Specify in the comment which points have you addressed in the patch #8 which will help me to understand.
Although the patch is not applying.
Comment #11
chiranjeeb2410 CreditAttribution: chiranjeeb2410 at Google Summer of Code commented@naveenvalecha,
patch #8 adrresses the points 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 19, 20, 21, 24, 25, 27, 29, 31, 32. 33.
Patch is not applying due to some probable errors. Working on the fixing the remaining issues and would upload a
correct patch today asap.
Comment #12
naveenvalechasounds good
Comment #13
chiranjeeb2410 CreditAttribution: chiranjeeb2410 at Google Summer of Code commentedComment #14
chiranjeeb2410 CreditAttribution: chiranjeeb2410 at Google Summer of Code commented@naveenvalecha,
Patch #13 adrresses the points 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 18, 19, 20, 21, 24, 25, 27, 29, 31, 32. 33.
Please review.
Comment #15
naveenvalechaAdd the route name in the configure link See user.info.yml for reference https://api.drupal.org/api/drupal/core%21modules%21user%21user.info.yml/...
Where is this base route defined?
Add a use statement of Url class at the top of the file and use only Url::fromRoute method instead of whole name space.
Why this change?
Why change in the permission title?
looks good :)
Where is this permission defined?
use "access wish lists" permission here
rename this service to "uc_wishlist.manager"
Rename DBQuery class to UcWishlistManager class and inject the connection object into it. See user.services.yml
Here's one of the service
user.data:
class: Drupal\user\UserData
arguments: ['@database']
Comment #16
chiranjeeb2410 CreditAttribution: chiranjeeb2410 at Google Summer of Code commented@naveenvalecha,
On it.
Comment #17
chiranjeeb2410 CreditAttribution: chiranjeeb2410 at Google Summer of Code commented@naveenvalecha,
Addressed all the listed issues in #16.
Please review.
Comment #19
chiranjeeb2410 CreditAttribution: chiranjeeb2410 at Google Summer of Code commentedUploading correct patch asap
Comment #20
chiranjeeb2410 CreditAttribution: chiranjeeb2410 at Google Summer of Code commentedComment #21
chiranjeeb2410 CreditAttribution: chiranjeeb2410 at Google Summer of Code commentedComment #23
chiranjeeb2410 CreditAttribution: chiranjeeb2410 at Google Summer of Code commented@naveenvalecha,
for fix 10 in #15, the DBQuery class name in all the files should be renamed to UcWishlistManager ?
Comment #24
naveenvalechaIf you're renaming a class then its usage should also be replaced.
Comment #25
chiranjeeb2410 CreditAttribution: chiranjeeb2410 at Google Summer of Code commented@naveenvalecha,
Did that for the previous 2 patches, but there are some other probable errors I guess. Will fix and post a fresh patch soon.
Comment #26
chiranjeeb2410 CreditAttribution: chiranjeeb2410 at Google Summer of Code commentedComment #28
chiranjeeb2410 CreditAttribution: chiranjeeb2410 at Google Summer of Code commented@naveenvalecha,
Addressed all the issues but patch doesnt seem to apply again. Could you check the code once ?
Comment #29
naveenvalecha@chiranjeeb2410
post the workable patch. See how to make the patch and apply the patch https://www.drupal.org/patch/apply
Comment #30
chiranjeeb2410 CreditAttribution: chiranjeeb2410 at Google Summer of Code commentedComment #32
chiranjeeb2410 CreditAttribution: chiranjeeb2410 at Google Summer of Code commentedComment #33
chiranjeeb2410 CreditAttribution: chiranjeeb2410 at Google Summer of Code commented@naveenvalecha,
Addressed the listed issues for #2 and all the issues for #15 in fresh patch. Kindly clone the uc_wishlist repo
and apply the patch.
Please review.
Comment #34
naveenvalechaInject the UCWishlistManager service in the controller. See https://www.drupal.org/docs/8/api/services-and-dependency-injection/serv...
Also, see this example in a UserController https://api.drupal.org/api/drupal/core%21modules%21user%21src%21Controll...
Add a comment here. "Construct an UcWishlistManager object."
Also, add the param documentation. https://www.drupal.org/docs/develop/coding-standards/api-documentation-a...
Add the doc block on this function. See coding standards https://www.drupal.org/docs/develop/coding-standards/api-documentation-a...
Add the appropriate comment here
same as above.
same as above.
same as above.
same as above.
same as above.
Add the docblock to this function.
Add the documentation for this function.
Add the documentation for this function.
Add the documentation for this function.
Add the documentation for this function.
Add the documentation for this function.
Is it required? if not, remove it.
Inject the uc_wishlist.manager service. See https://www.drupal.org/docs/8/api/services-and-dependency-injection/depe...
Inject this service in the form. See how to inject it https://www.drupal.org/docs/8/api/services-and-dependency-injection/depe...
Where is this parent defined?
use \Drupal::service to call this service.
Where's the use statement of the Order class?
use \Drupal::service to call this service.
use \Drupal::service to instantiate the object of this service class.
use \Drupal::service to instantiate the object of this service class.
use \Drupal::service to instantiate the object of this service class.
use \Drupal::service to instantiate the object of this service class.
use \Drupal::service to instantiate the object of this service class.
Add a newline at EOF
Comment #35
chiranjeeb2410 CreditAttribution: chiranjeeb2410 at Google Summer of Code commented@naveenvalecha,
On it.
Comment #36
chiranjeeb2410 CreditAttribution: chiranjeeb2410 at Google Summer of Code commented@naveenvalecha,
For statically accessing the service in .module file,
would be changed to
?
Comment #37
naveenvalecha#36: Yes
Comment #38
chiranjeeb2410 CreditAttribution: chiranjeeb2410 at Google Summer of Code commented@naveenvalecha,
Okay, finished those parts regarding DI in forms and controllers, working on the documentation part
now. Will upload a patch shortly.
Comment #39
chiranjeeb2410 CreditAttribution: chiranjeeb2410 at Google Summer of Code commented@naveenvalecha,
Addressed all the above listed issues in #34.
Please review.
Comment #40
naveenvalechaGreat progress, this is near to RTBC.
rename this property to $wishlistManager because it better reflects the service name.
rename $db to $wishlist_manager
$this->wishlistManager = $wishlist_manager;
Constructs a UcWishlistManager object.
Add a description/comment of the function above the return statement.
Remove the commented line and add a comment in next line with a todo of adding the pager
Add the descriptions of the $fields and $values property.
What's the use of $query variable? If it's not required, remove it.
Add the descriptions of the $fields and $values property.
What's the use of $query variable? If it's not required, remove it.
Add the descriptions of the function.
Add the return type of the function.
What's the use of $query variable? If it's not required, remove it.
Add the descriptions of the function.
Add the description of the $data
Add the return type after @return. Follow the coding standards document
What's the use of $query variable? If it's not required, remove it.
Add the description of the function.
Add the return type.
Remove the commented line and add a comment in next line with a todo of adding the pager
Add the description of the function.
Add the return type
What's the use of $query variable? If it's not required, remove it.
Add the description to the function.
Add the description to the $rid and $created variable.
Add the description to the function.
Add the return type.
Add the description to the function.
Add the return type.
What are you returning here?
Add the description to the function.
Add the return type.
Add the description to the function.
Add the return type.
What's the use of $query variable? If it's not required, remove it.
Add the description to the function.
Add the return type.
Add the description to the function.
Add the return type.
Property name should reflect the service name. Rename it to $ucwishlistManager
UcWishlistManager $ucwishlist_manager
$this->ucWishlistManager = $ucwishlist_manager;
There's no need to statically instantiate the object of the service. It will be available as $this->wishlistManager because it's injected above in the constructor.
It's the comment/description of the Class, so remove @file from the comment.
Inject the currentUser service using DI in the form.
use $this->t
use $this->t
Where's this function?
use $this->t
Inject the current user service in this class.
Rename this property to $ucwishlistManager
UcWishlistManager $ucwishlist_manager
$this->ucwishlistManager = $ucwishlist_manager;
you could access this service using $this->ucwishlistManager
rename variable name to $wishlist_manager instead of $db
rename variable name to $wishlist_manager
rename variable name to $wishlist_manager
rename variable name to $wishlist_manager
rename variable name to $wishlist_manager
rename variable name to $wishlist_manager
Comment #41
chiranjeeb2410 CreditAttribution: chiranjeeb2410 commented@naveenvalecha,
Thanks. Working on the final part.
Will submit fresh patch shortly.
Comment #42
chiranjeeb2410 CreditAttribution: chiranjeeb2410 commented@naveenvalecha,
Addressed the issues listed in #40.
Please review.
Comment #43
chiranjeeb2410 CreditAttribution: chiranjeeb2410 commentedComment #44
chiranjeeb2410 CreditAttribution: chiranjeeb2410 commented@naveenvalecha,
Please review.
Comment #45
naveenvalechaAdd the description/comment
Add the description and add the comment for @param
Add the description here
Add the return statement as well i.e. return $this->connection
Method name is not per coding standards. It should be removeItem
same as above. add the return as well.
Method name is not per coding standards. it should be removeProduct
same as above.
use the common pattern across the code either use the wishlistManager/ucWishlistManager In above controller you have defined the property name $wishlistManager
Typehint the class with full namespace i.e. \Drupal\Core\Session\AccountInterface
Add the description i.e. Constructs an UserWishlistSettingsForm class.
are you sure it's uc_product.settings or uc_wishlist.settings
Is this local variable requied. can't $this->account gets used everywhere?
Typehint it with full namespace.
Is this local variable requied. can't $this->account gets used everywhere?
Is this local variable required? can't $this->ucwishlistManager be used?
Does this commented code really require?
Does this commented code require?
Does this commented code require?
Comment #46
chiranjeeb2410 CreditAttribution: chiranjeeb2410 commented@naveenvalecha,
Addressed all the above listed issues.
Please review.
Comment #47
naveenvalechaphew :( you didn't test the code before posting the patch.I'm getting WSOD while enabling the module. See the screenshot attached. Let me know if you need any help.
P.S.: I'm tired of requesting this thing again and again in the several issues to test the code before posting the patch because of untested code waste of time of both parties.
Comment #48
naveenvalechaUpdating Issue summary
Comment #49
chiranjeeb2410 CreditAttribution: chiranjeeb2410 commentedComment #50
naveenvalechaYay! This is super neat!
A lot of coding standards are missing. See https://www.drupal.org/pift-ci-job/756133
Fixed some coding standards by running phpcbf on it
phpcbf --standard=Drupal uc_wishlist/
Comment #51
naveenvalechaCoding standards messages are down from 471(https://www.drupal.org/pift-ci-job/756133) to 94(https://www.drupal.org/pift-ci-job/756160)
Fix these coding standards warnings https://www.drupal.org/pift-ci-job/756160
Once this will be done. I'll thoroughly review and test the patch.
Comment #52
chiranjeeb2410 CreditAttribution: chiranjeeb2410 commented@naveenvalecha,
On it.
Comment #54
naveenvalechaCommitted and pushed to 8.x-1.x because the patch is gonna big.
Still, there are a lot of issues to address. Filed a follow-up for that #2907204: UC Wishlist review - Part 2
Comment #55
chiranjeeb2410 CreditAttribution: chiranjeeb2410 commentedThanks. Working on the remaining issues.