CVS edit link for Stutzer

Hi, I'm leading developer of labs42.com web-studio, Russia.

I want to contribute module named «Handy alias» that provide easy way to attach aliases to vocabularies, terms and nodes. Further this aliases can be used for building structure-corresponding paths with «pathauto» module using this aliases as a parts of the whole path.

This functionality is not so obviously useful for English-language sites, as they use to build aliases based on term/node titles. But for localized sites it's very important to have opportunity for specifying aliases that is not just transliteration of object(term/node) title.

Little example: we have vocabulary «Motor vehicles types»
There we have tree-structured terms like:
- Truck
- Passenger car
---- Hatchback vehicles
---- City vehicle
-------- Micro vehicle
etc…

Also we have content type «Motor vehicles» categorized with this «Motor vehicles types» vocabulary.
And now we want paths of Motor vehicles nodes look like this: autos/pass-cars/city-cars/micro-cars/some-node-alias.html
and paths of terms look like «autos/pass-cars/city-cars»

We can easy realize this needs with «Handy Alias» module with next few steps:
1. Enable «handy alias» for «Motor vehicles types» vocabulary, set «autos» alias for this vocabulary (see http://www.labs42.com/_img/handyalias_vocab_form.png)

2. Set alias for each term of this vocabulary:
Passenger car ---> pass-cars
City vehicle ---> city-cars
Micro vehicle---> micro-cars
Hatchback vehicles ---> hatchbacks
Truck ---> trucks
(see http://www.labs42.com/_img/handyalias_term_form.png)
(again, importance of this ability it's not so obvious when terms named in English)

3. Go to pathauto patterns page and set following pattern for «Motor vehicles» content type:
[vocab-handy-alias]/[term-handy-alias-path]/[node-handy-alias]

[vocab-handy-alias] will return «autos»
[term-handy-alias-path] will return, for say, «pass-cars/city-cars/micro-cars»
[node-handy-alias] will return «some-node-alias.html» or node id if node alias if empty.

Also «Handy Alias» module allows specifying node aliases, if this feature is enabled for content type. Handy alias feature setting for content type: http://www.labs42.com/_img/handyalias_ctype_form.png
Specify handy alias for node: http://www.labs42.com/_img/handyalias_node_form.png

I haven't found any similar modules, so I hope Drupal community will find it useful.

Comments

avpaderno’s picture

Hello, and thanks for applying for a CVS account.

As per instructions, the archive containing the module needs to be attached in a comment here; without that, this CVS application cannot continue.

Stutzer’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new8.27 KB

Handy Alias module source code

avpaderno’s picture

Issue tags: +Module review
Stutzer’s picture

StatusFileSize
new8.07 KB

Some improvements:
* Fix dependencies
* Some minor fixes

Stutzer’s picture

StatusFileSize
new8.07 KB

* Several tiny bug fixes
* Some comments

Has anyone tried to use it? Any comments?

avpaderno’s picture

Status: Needs review » Needs work
  • The points reported in this review are not in order or importance / relevance.
  • Most of the times I report the code that present an issue. In such cases, the same error can be present in other parts of the code; the fact I don't report the same issue more than once doesn't mean the same issue is not present in different places.
  • Not all the reported points are application blockers; some of the points I report are simple suggestions to who applies for a CVS account. For a list of what is considered a blocker for the application approval, see CVS applications review, what to expect. Keep in mind the list is still under construction, and can be changed to adapt it to what has been found out during code review, or to make the list clearer to who applies for a CVS account.
  1. Hook implementation comments should be like the following one:
    /**
     * Implements hook_menu().
     */
    
  2. /**
     * Remove all variables crated by this module
     */
    function _handyalias_remove_variables() {
      $result = db_query("SELECT v.name FROM {variable} v WHERE v.name LIKE 'handyalias%';");
      while ( $item = db_fetch_object($result) ) variable_del($item->name);
    }
    

    Deleting Drupal variables using a query that matches any Drupal variable with a name that starts with the module name would remove also the Drupal variables of other modules.

  3. require('handyalias.lib.inc');
    
    

    There is a Drupal function to use to load PHP files.
    It usually not a good idea to unconditionally include code contained in PHP files. If the files contain form handlers, theme functions, or menu callbacks, Drupal core code allows to third-party modules to define which files must be loaded in the implementations of hook_menu(), and hook_theme(); in these cases, Drupal loads the file only when necessary.

  4. See http://drupal.org/coding-standards to understand how a module should be written. In particular, see how constant names should be written; how the code should be formatted.
  5.    '#description' => t('Here you can set vocab alias, enable Handy Alias feature for terms of this vocabulary and select content types this vocabulary can be used for as an URL-alias constructor.'),
    
    

    It should be vocabulary.

  6.     $form['identification']['alias_markup'] = array(
         '#type' => 'markup',
         '#value' =>
             '<div class="messages error">'
           .   t('Unable to use Handy alias functionality with this vocabulary as it have incompatible configuration. We don`t know how could it happend.<br/>You shouldn`t use "Tags", "Multiply terms" and "Multiply hierarchy" in vocabulary')
           . '</div>',
         '#weight' => 0,
        );
    
    

    Why isn't the code using drupal_set_message()?

  7. function _handyalias_alias_validate(&$element, &$form_state) {
      if ( !empty($element['#value']) ) {
        if ( !_handyalias_valid_alias($element['#value']) )
          form_error($element, t('Invalid alias. Only latin characters, digits, underscore, dash, dot and plus are alowed'));
      }
    }
    
    

    It should be allowed.

  8.       return db_result( db_query("SELECT `alias` FROM {handy_alias} WHERE `oid` = '%d' AND `type` = '%d'", $oid , $type) );
    
    

    The character ` is not used from all the database engines for which Drupal is compatible.

Stutzer’s picture

Status: Needs work » Needs review
StatusFileSize
new8.26 KB

kiamlaluno, thank you very much for your review!
Fixed all your points and made some slight improvements.
Also reviewed code by coder module and fixed almost all coding-standards deviations.

avpaderno’s picture

Assigned: Unassigned » avpaderno

I will review the code tomorrow.

avpaderno’s picture

Status: Needs review » Fixed
  1.   if ( is_array($vocab_settings_all) && !empty($vocab_settings_all) ) {
        foreach ( $vocab_settings_all as $vocab_id => $ctypes ) {
          if ( is_array($ctypes) && !empty($ctypes) && $vid != $vocab_id ) {
            foreach ( $ctypes as $ctype ) {
              $reserved_ctypes[] = $ctype;
            }
          }
        }
      }
    
    

    should be

      if (is_array($vocab_settings_all) && !empty($vocab_settings_all)) {
        foreach ($vocab_settings_all as $vocab_id => $ctypes) {
          if (is_array($ctypes) && !empty($ctypes) && $vid != $vocab_id) {
            foreach ($ctypes as $ctype) {
              $reserved_ctypes[] = $ctype;
            }
          }
        }
      }
    
    

    As per coding standards, there should not be any spaces after an open parenthesis.

  2.     drupal_set_message(
          t(
            'You just has changed vocabulary alias. To update existing aliases up to new alias use "<a href="!url">Bulk update</a>" page of pathauto module',
            array( '!url' => url('admin/build/path/update_bulk') )
          ),
          'warning'
        );
    
    

    The placeholder for URLs must start with @.

Thank you for your contribution! I am going to update your account.

These are some recommended readings to help with excellent maintainership:

You can find more contributors chatting on the IRC #drupal-contribute channel. So, come hang out and stay involved.
Thank you, also, for your patience with the review process.
Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

I thank all the dedicated reviewers as well.

Stutzer’s picture

Thank you, Alberto!
Reading about CVS rules, project maintaining etc. and publish my module.

Status: Fixed » Closed (fixed)
Issue tags: -Module review

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

avpaderno’s picture

Component: Miscellaneous » new project application
Issue summary: View changes
avpaderno’s picture