Wednesday, May 25, 2011

Adding database content directly for a CCK content type (dynamic content)

source:  http://drupal.org/node/343373

 

Don't add to the db directly

A Drupal node is fairly complex, so you probably don't want to add content directly to the database. Instead, you have several options:
1) Use an existing module that can handle CCK (see http://drupal.org/project/Modules/category/64)
2) Use http://drupal.org/project/node_factory, which provides an API for programmatically creating nodes
3) Use a lower-level approach like the one described at http://acquia.com/blog/migrating-drupal-way-part-i-creating-node
The last one is the most flexible, of course.
Mark

Tuesday, May 24, 2011

Input formats no longer showing up as options in Views 2

http://drupal.org/node/418438

For me, it was "image assist"

For me, it was "image assist" - I had disabled and re-enabled at some point. Image assist options changed on re-enable so that it was appearing on all paths instead of being restricted to node and comment paths which is usually the default. Resetting to default and restricting to node and comment paths fixed the problem and input formats is restored in views.

Friday, May 13, 2011

Use Views module to create a tab in user page

In page display in a view, you can choose menu tab to menu of the page settings.
Use flag module to implement user collection such as my favorite (relationship between flag and node)

flag moduleuse flag and view combine the data. User can use flag link to add or delete the flag relationship.
 
1) In the view, you need to add the relationship to mapping the node and the flag. Need to take care of Include only flagged content setting. If checked, only user flag node would be showed.

2) Use views flag refresh module to update view when flags are selected.
Views Flag Refresh is configured entirely through the Views interface. After installing the module, additional settings will be available to the Use AJAX option in each display's Basic Settings tab.
Make table in View sortable

Source: http://www.lornajane.net/posts/2009/Sortable-Views-in-Drupal-6


Drupal already has a way to do this!

  1. Edit the view you want to add the column sorting to
  2. Under "Basic Settings", look for "Style: Table" and click on the picture of a cog next to it. (if I were a serious blogger, I'd screenshot. Never mind, eh?)
  3. Scroll down to see the table settings
  4. There is a list of the fields, and a tickbox for each labelled "sortable" - tick the boxes for any columns you want users to be able to change the sort order on
 The taxomony in the Table cannot be sortable. To solve this problem, you need to use taxomony field (content taxomony). Then set the view as following:

How to add sort for content taxonomy fields

pimousse98 - Tue, 2010-03-09 23:13
Hi Agaron,
Try the following
1. Add a relationship for your content taxonomy field (click the + in "relationships" and choose content:Size or similar)
2. Add a field in your table that is Taxonomy:Term (and not content:Size). In the Relationship: drop-down, choose "content:Size term" or something similar (whatever you called your relationship in step 1.). Set up the rest of your field as usual.
3. Click the options symbol right next to style:table in the "basic settings" section. You will see a list of fields and there should be a "sortable" checkbox next to field you just added. Check it and save.
Your field should now be sortable by clicking on the table headers.
I have not tried it with node reference but I suspect it might work as well, if you get the right combination of relationships.

How to sort by term weight not alphabetically
Source: http://drupal.org/node/272424 


Great tip in #3, thank you.
For those interested, you can extend this a little bit to sort not alphabetically, but by term weight. That'll allow you to reorder terms at admin/content/taxonomy and have the sorting respect that order. Useful for sequences like "low, medium, high".
Add the relationship, and per instructions above, add the "Taxonomy: Term" field. Also, add the "Taxonomy: Weight" field. Configure the Term field as you need it, and check "Exclude from display".
On the Weight field, check "Rewrite the output of this field", and enter the token for the term field you have above. The naming convention isn't very nice in that it's hard to tell which field is the one you need. For me they looked like "[name_1]", "[name_2]", etc.
Now the weight field is what Views is showing and doing sorting on, but thanks to the rewrite the Term field is actually displayed.




    Thursday, May 12, 2011

    Friday, April 22, 2011

    Use Tab Tamer module to remove the tabs (Drupal defaults in the system) that you dont want.

    for example, EDIT tab in user page.
    User Editview module to change views to be editable

    Futhuer more, modify or add templete.php in the theme to make the fields showed vertically:

    ( if you do not know about templete.php, you can refer to template.php: Overriding other theme functions):

    Soure: http://drupal.org/node/581488#comment-4378324

    • override the theme_editview_node_form() function (by copying it into my template.php file, and renaming it to MYTHEME_editview_node_form()).
    • comment out or delete this line:
                  $header[] = $field->label();
    • Add this line...
                  $cell['data'] .= "";
      ...just before this one:
                  $cell['data'] .= $value;
    • Change...
                  $row[] = $cell;
      ... to
                  $rows[] = array($cell);
    • Change...
                  return theme('table', $header, array($row), array('class' => 'editview-row')) . $buttons;
      ... to
                  return theme('table', $header, $rows, array('class' => 'editview-row')) . $buttons;
    Also, in the view itself, I set the "label" of all *checkbox* fields to display as 'none', because otherwise the you get the same label before and after the checkbox. For other types of fields, I left it set to "widget label".
    That was my fix, and it works well. Ideally, this theme function should be rewritten to remove the logic-work out into its own function, and leave the theme_...() function as only showing how to display the data. That would make overriding the theme function less clunky.

    Tuesday, April 19, 2011

    Add a link(such as add to my favorite) to make the node referenced with View

    source:  http://drupal.org/node/765562#comment-2822990

    my related post: http://wadmin.blogspot.com/2011/04/display-suite-module-for-customizing.html

    The use of a View to restrict the list of nodes simply reduces the nodes that may be referenced. Maybe you'd want to make a list of referenceable nodes that only includes content created in the last 30 days, content promoted to the front page, or some other arbitrary properties. In your case it sounds like you wouldn't use this functionality since "feedback" nodes should be able to reference any "proof" node. This functionality doesn't have anything to do with adding links to the display of a view.
    If you want to add a link to "Add feedback" to a piece of content, add the Node: NID field and then rewrite it so that it is a link "Add Feedback" with the path "node/add/feedback/[node_nid]". Assuming you've set up the feedback content type with a Node Reference URL Widget, it will pull the nid from the URL and prepopulate the field.

    THAT IS:
    Make Node: NID to be a link by "rewrite the output of this file" and "Output this field as a link"
    Translation of the name of the content type.
    Source:  http://drupal.org/node/763536

    Use translation interface to translate the name of the content type. However, there is a bug in i18n. When you click content create, the content names are not translated.

    Solution: with following patch.

    # This patch file was generated by NetBeans IDE
    # Following Index: paths are relative to: \sites\all\modules\downloaded\i18n\i18ncontent
    # This patch can be applied using context Tools: Patch action on respective folder.
    # It uses platform neutral UTF-8 encoding and \n newlines.
    # Above lines and this line are ignored by the patching process.
    Index: i18ncontent.module
    --- i18ncontent.module Base (BASE)
    +++ i18ncontent.module Locally Modified (Based On LOCAL)
    @@ -156,13 +156,16 @@
      */
     function i18ncontent_menu_alter(&$menu) {
       $menu['node/add']['page callback'] =  'i18ncontent_node_add_page';
    -  // @TODO avoid iterating over every router path.
    -  foreach ($menu as $path => $item) {
    -    if (!empty($item['page callback']) && $item['page callback'] == 'node_add') {
    + //fetch valid node types
    + //we just copy the behavior in node_menu()
    + $ntypes = node_get_types('types', NULL, TRUE);
    + foreach ($ntypes as $type) {
    +    $type_url_str = str_replace('_', '-', $type->type);
    +  $path = 'node/add/' . $type_url_str;
    +    if (!empty($menu[$path]['page callback']) && $menu[$path]['page callback'] == 'node_add') {
           $menu[$path]['page callback'] = 'i18ncontent_node_add';
    -      $arg = arg(NULL, $path);
           $menu[$path]['title callback'] = 'i18nstrings_title_callback';
    -      $menu[$path]['title arguments'] = array('nodetype:type:'. $arg[2] .':name', $item['title']);
    +      $menu[$path]['title arguments'] = array('nodetype:type:'. $type->type .':name', $type->name);
         }
       }
     }
    Drupal SEO modules
    http://www.kristen.org/content/drupal-seo-modules

    Monday, April 18, 2011

    Use google analysis
    Modules for relations of nodes and display them

    Use node reference, node reference view, view attach and corresponding node reference to make related blocks beside the node.

    Corresponding node reference is helpful for bidirectional relations. Note: Corresponding node reference may have problem with a translated node to a non-translated node.

    Use Node reference url for users to establish referred relation between nodes.

    Use display suite to adjust the desplay of them.

    Sunday, April 17, 2011

    Views: Using explosed filter to make a search form.

    source: http://drupal.org/node/545592

    If you want a separate block for the exposed filter, this should be set to Yes. If you want the filter to be in the View's Block display, make sure that the Block display's "Exposed form in block" option is set to No.
    Depening on the configuration you're attempting to achieve, you might want to override your default settings.
    Show nothing with empty argument

    source: http://drupal.org/node/358546

    Add an argument of type "Global: Null". (This argument doesn't alter any behaviour directly).
    Configure the new argument to:
    • display all values if the argument is not present
    • display empty text if the argument does not validate
    Now change the validator to the following PHP code (without the opening and closing PHP tags of course):
    // The exposed_input array has values only when
    // the exposed filters have been submitted.
    if (count($view->exposed_input)) {
      return
    TRUE;
    }
    ?>
    When you visit your view with any argument (e.g. mysite.com/myview/start) the validator will run, find exposed_input empty and display your view's empty text. Once you hit submit on the filter it'll run as usual.
    In my case I can live with the extra argument. Hopefully you can too, or at least this'll give you something to start from.

    Tuesday, March 22, 2011

    How to apply random items in a view
    source: http://drupal.org/node/78111
    1. create a new view in administer » views » add tab.
    2. give it a name. I called mine "Random".
    3. click the "Block" section heading to get its settings.
    4. enable "Provide block"
    5. choose a "View type". I went with "List View" so that I could choose which fields display in the block.
    6. type in a title. This will be the title of the block.
    7. type in a number for the amount of nodes you want to display in the block. You can use 1 (number one) if you like.
    8. click the "Fields" section heading to get its settings.
    9. add the fields you want. I chose just "Node: Title" since I wanted just links to the nodes, not the node text themselves. You should be able to choose whichever field has the quote in your CCK node.
    10. click the "Filters" section heading to get its settings.
    11. select "Node: Type" and click "Add Filter"
    12. choose the CCK node type(s) you want to appear in the block.
    13. select "Node: Published" and click "Add Filter". (I keep forgetting this one, but it's important, since you probably don't want to display unpublished nodes.
    14. click the "Sort criteria" section heading to get its settings.
    15. select "Random" and click "Add criteria". (In views2, simply add the Sort criteria of Global:Random)
    16. click "Save"
    17. click administer » blocks and enable the block you titled in step #6.

      Monday, March 14, 2011

      In Ubercart: remove "Click here to view your order history" if the user does not have orders.

      excerpt from : http://www.ubercart.org/forum/support/17823/hide_click_here_view_your_order_history_link_if_user_has_no_order_history


      Here's a quick & dirty patch to hide the "Click here to view your order history" section of the user page if the user has no order history to view. It leaves the Orders tab alone, so the (empty) order history is still accessible; only the misleading link is removed.
      in version 1.12.2.40 of uc_order/uc_order.module, change
      function uc_order_user($op, &$edit, &$account, $category = NULL) {
        global
      $user;
        switch (
      $op) {
          case
      'view':
            if (
      $user->uid && (($user->uid == $account->uid && user_access('view own orders')) || user_access('view all orders'))) {
             
      $account->content['orders'] = array(
               
      '#type' => 'user_profile_category',
               
      '#weight' => -5,
               
      '#title' => t('Orders'),
               
      'link' => array(
                 
      '#type' => 'user_profile_item',
                 
      '#value' => l(t('Click here to view your order history.'), 'user/'. $account->uid .'/orders'),
                ),
              );
            }       break;
        }
      }
      ?>




      to
      function uc_order_user($op, &$edit, &$account, $category = NULL) {
        global
      $user;
        switch (
      $op) {
          case
      'view':
            if (
      $user->uid && (($user->uid == $account->uid && user_access('view own orders')) || user_access('view all orders'))) {
             
      $result = db_fetch_object(db_query("SELECT o.order_id FROM {uc_orders} AS o WHERE o.uid = %d AND o.order_status IN ". uc_order_status_list('general', TRUE), $user->uid));
              if (!
      $result) return;
             
      $account->content['orders'] = array(
               
      '#type' => 'user_profile_category',
               
      '#weight' => -5,
               
      '#title' => t('Orders'),
               
      'link' => array(
                 
      '#type' => 'user_profile_item',
                 
      '#value' => l(t('Click here to view your order history.'), 'user/'. $account->uid .'/orders'),
                ),
              );
            }       break;
        }
      }
      ?>
      (The two lines involving $result are the ones that have been added.)
      Hope this helps someone besides myself!

      Friday, March 04, 2011

      Modification in drupal for making filefield works.  This info was posted in http://drupal.org/node/313539 too. Please refer it for complete info.

      Title: Compatiblity with FileField: private_upload cannot work with filefield without modification of code.
      ...

      I finally found the problem.
      It is because in Private_upload.module the hook of download. If I change "return -1" to "return", then it works perfectly for the files uploaded by CCK-filefield into the priavte area (directory). Of course, this is not a solusion since all the attached file will not have access control at all.
      With a little more code tracking, I realized that there is no information related to filefield upload in the Database, if I upload files with CCK-filefield. Therefore, with
      $result = db_query("SELECT DISTINCT(u.nid) FROM {upload} u INNER JOIN {files} f ON u.fid = f.fid ".
      "WHERE f.filepath = '%s'", $filepath);
      $result will be empty and hence all the downloading is blocked no matter who is the user (even admin).
      With this conclusion, private upload cannot work with filefield without modification of code. Since paivate file attachment is not importatn to me, to have access control for file of the filefield. My solusion right now is disable private upload and:
      1) Put an .htaccess in a private directory to give access control to Drupal.
      2) Use filefield_path to set private directory of the protected filefield so that the upload files of the protected filefield go to the private direcotry.
      If anyone thinks something wrong about the solusion, please let me know.
      hosais
      ============================
      The hock of file download() in private upload module.
      ============================
      function private_upload_file_download($file) {
      $private_dir = variable_get('private_upload_path', 'private');
      if(_private_upload_starts_with($file, $private_dir)) {
      $filepath = file_create_path($file);
      $result = db_query("SELECT DISTINCT(u.nid) FROM {upload} u INNER JOIN {files} f ON u.fid = f.fid ".
      "WHERE f.filepath = '%s'", $filepath);
      while($row = db_fetch_array($result)) {
      $node = node_load($row['nid']);
      if (node_access('view', $node)) {
      return; // Access is ok as far as we are concerned.
      }
      }
      return -1; // No nodes are granting access, so veto download. <--- CHANGE THIS to return;
      }
      }

      Monday, September 28, 2009

      Want to make your Drupal showed on mobile phone?

      Check the module mobile_tools in the following link. It would detect the source and change presentation of the web.

      http://drupal.org/project/mobile_tools

      Sunday, July 06, 2008

      Domain Access Advanced Usage

      Below is excerpt from the README in the domain access module. To set the advanced usage (means that the domain editor is not only one administrator who can edit/delete all the content if necessary. The domain editor can access the contents belong to the same domain).

      In Readme.txt

      3.3 Advanced Usage

      In the event that you wish to segregate which content certain editors can control, you should not use the normal 'edit TYPE nodes' permission provided by Drupal's core Node module.  This permisson grants the ability for a user to edit all nodes of a given type.

      In the Domain Access model, this permission is not used in favor of the provided 'edit domain nodes' permission.  This permission allows editors only to edit (and delete) nodes that belong to their subdomain.

      To enable this feature, you should grant the 'edit domain nodes' permission to some roles.  Then you should enable the 'Use access control for editors' setting under the Domain Access configuration screen.