CVS edit link for WebNewCastle

Hello,

My understanding is that we need to obtain a CVS account in order to contribute a module to the Drupal Community.

Initially, I would like to contribute a module that provides simple options for specifying a particular node template to be used on a node-by-node basis (or by content type). This can be done when adding or editing a node by choosing the node template to be used from a list of available node.tpl files in a theme. A default option is also available that would assign the node template to be used from a similar setting in the content types administrative page or or based on default node template suggestions.

My understanding is that there are fewer default options for node template suggestions than page template suggestions, and that node template suggestions are generally limited to content type only. As far as I know from researching contributed modules, I don't believe there is a module that provides a simple solution for overriding a node template on a node-by-node basis.

There are some modules that provide similar options in regards to page templates and block templates. I believe it would also be useful to do this with nodes as well in a number of ways. Although in many cases, one may wish to style and display nodes based on content type, this isn't always the case. And especially where CCK fields can be shared across content types, it would be useful to have additional options to display nodes besides content type. For example, if one wanted to display a particular node with different display settings of CCK fields than the default, one can create a specific node.tpl file to the theme and then choose that template for the particular node.

Please let me know if you have any questions. I've tried to understand this process for using CVS and contributing back to the Community. I've benefited greatly from Community contributions, and I look forward to contributing myself. I also wish to contribute back some themes, but these aren't quite ready for contribution.

Sincerely,

Matt

P.S. I was going to call the module "Node Template", but there is a previous contribution with that name - the functionality and purpose of that module is completely different. I was then going to name it "Node Theme", but that name is used by another contribution which changes the theme for a node (not the template within a theme). The next name I chose is "Custom Node Template", but I am very open to suggestions that will best identify the functionality for the community.

Comments

WebNewCastle’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new7.9 KB
avpaderno’s picture

Issue tags: +Module review
avpaderno’s picture

Status: Needs review » Needs work
  1.       '#title' => 'Node Template',
          '#description' => 'Select the node template for this node',
    

    Title and description should be translatable.

  2.       '#title' => t('Node Template Settings'),
    

    Strings used in user interface should have the first word in capital case, and the other words in lower case (with the exception of proper nouns, adjectives derived from proper nouns, and acronyms).

  3.   $handler = opendir($theme_path);
      while ($file = readdir($handler)) {
        if ($file != '.' && $file != '..' && drupal_substr($file, 0, 4) == 'node') {
          $name = drupal_substr($file, 0, -8);  // name without .tpl.php
          $options[$name] = $name;
        }
      }
      closedir($handler);
    

    The code could use file_scan_directory().

  4.     'description' => t('Custom Node Template table'),
    

    Schema description should not be passed to t(). See system_schema() for an example of what done by Drupal core code.

  5. The file LICENSE.txt needs to be removed; Drupal.org CVS doesn't allow to commit that file.
  6. The uninstallation function should also remove the Drupal variables used by the module.
WebNewCastle’s picture

Thank you.

Regarding #1, is the following the applicable information in reference to what you described?

http://drupal.org/node/299085

avpaderno’s picture

t() is mandatory for every string used in the user interface; the only cases where its use is not mandatory for third-party modules code is when the function is called from Drupal core code for those modules (see the case of the menu callbacks title, for which the string is passed to t() from Drupal core code).

WebNewCastle’s picture

Thank you. I've made all the changes except for #3 - I am just trying to figure out file_scan_directory.

WebNewCastle’s picture

I seem to still be having issues linking the results of file_scan_directory back into the rest of the code. Do you have any suggestions for further research on file_scan_directory for how it can be used for this module? Or is #3 not a necessary part for this module? The other items in the list have been completed. I'll add the updated version pending a decision about #3. Thanks!

WebNewCastle’s picture

Status: Needs work » Needs review
StatusFileSize
new2.65 KB
avpaderno’s picture

file_scan_directory() returns an array of objects where each object represent a file (the function doesn't return directories).
Modules should use Drupal functions, when available.

Just to make an example, this is the result returned by file_scan_directory(drupal_get_path('theme', 'garland'), '.*\.tpl.php', array('.', '..', 'CVS'), 0, FALSE) (the result has been passed to var_export()):

 array (
  'themes/garland/block.tpl.php' => 
  stdClass::__set_state(array(
     'filename' => 'themes/garland/block.tpl.php',
     'basename' => 'block.tpl.php',
     'name' => 'block.tpl',
  )),
  'themes/garland/comment.tpl.php' => 
  stdClass::__set_state(array(
     'filename' => 'themes/garland/comment.tpl.php',
     'basename' => 'comment.tpl.php',
     'name' => 'comment.tpl',
  )),
  'themes/garland/maintenance-page.tpl.php' => 
  stdClass::__set_state(array(
     'filename' => 'themes/garland/maintenance-page.tpl.php',
     'basename' => 'maintenance-page.tpl.php',
     'name' => 'maintenance-page.tpl',
  )),
  'themes/garland/node.tpl.php' => 
  stdClass::__set_state(array(
     'filename' => 'themes/garland/node.tpl.php',
     'basename' => 'node.tpl.php',
     'name' => 'node.tpl',
  )),
  'themes/garland/page.tpl.php' => 
  stdClass::__set_state(array(
     'filename' => 'themes/garland/page.tpl.php',
     'basename' => 'page.tpl.php',
     'name' => 'page.tpl',
  )),
)

You could pass a callback name to the function, which would be a function that saves the result in a variable, after it processed the names of the file as your code does.

WebNewCastle’s picture

Thanks. I was able to get it to work to return an array of just node tpl files. It's probably with the callback that I was having issues. Thanks for the example.

avpaderno’s picture

Status: Needs review » Fixed

My point about using file_scan_directory() is still valid; the code is still using substr() when it should use the Drupal function.

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.

WebNewCastle’s picture

Hi KiamLaLuno,

Yes, definitely. I got busy with work recently, but I do want to still work towards figuring out what I am missing with the integration of file_scan_directory () into the module code. Thank you for your assistance with questions and in general. I appreciate it. This has been a good experience for me.

- Matt

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
Assigned: Unassigned » avpaderno
Issue summary: View changes