Saturday, September 29, 2012

Node Menu Parent - Module

The Node Menu Parent module extends the "default menu for content" setting provided by the core menu module by allowing a specific menu item to be selected (not just a top-level menu) per content type.

Example

Imagine we're creating a site for a business that will have a section describing the products they offer. We've got the core content types, Page and Story, and we've added our own content type called Product. Then we add a few pages under the Primary links menu, like so:
  • <Primary links>
    • Products
    • Support
    • About Us
Now say we've decided that every product should have a menu item under Products. However, core Drupal's menu settings only let us choose a global default menu for content, such as Primary links. That means when we go to create a Product, the "Parent item" dropdown under "Menu settings" defaults to Primary links so every time we create a product we have to manually select Products as the parent item. This is tedious, easy to forget, and unnecessary extra clicking.
The Node Menu Parent module gives us an extra option under the content type settings to choose a specific parent menu item per content type. So we can go to edit the Product content type, choose the Products menu item as the default parent, and now when we go to create a new Product that menu item is automatically chosen for us.
Combined with a module like Auto Menu Title, we can have menu items for our products created automatically without ever looking at the menu settings.

Read More..

Tuesday, September 25, 2012

jcarousel view returns empty row


  • Go its Views settings.
  • Add a relationship. Search for "fid" in the list and check the field your jCarousel is using.
  • Add an extra filter criterion. Search for "fid" and once again: check the same field.
    • Using these settings for this field: Operator: is not empty (NOT NULL)
  • Save

Menu Browser - Module

Makes it easier for editors to place their content exactly where they want it inside their menus.
This module adds a menu browser to the content forms. Users don't choose "parent" and "weight" for the menu item they are adding. Instead they choose a menu, and the menu gets loaded using ajax. The users then places the menu item inside the menu by clicking on the item they want to place the menu below. New menu items may also be placed as children of existing menu items.
To use this module install and enable it the normal way. It doesn't create any tables or variables. It replaces the menu part of the content forms.
This module should work well on touch-screen devices. (Only tested with Android devices so far)

Read More...

Monday, September 24, 2012

Overview-approach to block visibility

As of Drupal 5.x you can specify what roles can see a block through the block admin UI, but using PHP still gives you extra flexibility.
If you are going to set visibility on a lot of blocks, see Block Page Visibility
Review of how the role visibility works in Drupal 5
  • If no role check boxes are checked, block is visible to all roles.
  • If "authenticated user" is checked, all logged in users will see the block, checking any of the other role boxes (other than anonymous user) is meaningless.
  • Checking anonymous users means that logged-in users, unless they belong to another role that is also checked, will not see the block.
Basics of setting visability via PHP:
  1. Go to administer >> access control and ensure “administer blocks “ and “use PHP for block visibility” are checked for your role.
  2. Go to administer >> blocks and find the block you want to set the visibility for.
  3. Click “configure” next to that block.
  4. Under the section entitled, “Page specific visibility settings”, click the radio button for “Show if the following PHP code returns TRUE”
  5. In the text box provided, enter whichever of the following snippets meets your needs: 
Read More

Friday, September 21, 2012

PDF to ImageField - Module

The PDF To ImageField module provides automatic conversion of uploaded PDF files to images.
It can be used either to create a snapshot of the front page to use as a preview thumbnail, or to generate a gallery of images from each page in the document.
The module is implemented as an additional widget for File Field where PDFs are uploaded to. It places generated images into a Image Field on the same content type.

Read More ....

Thursday, September 20, 2012

Validation on Menu Link Title

function node_form_submit($form, &$form_state) {
      $item = &$form_state['values']['menu'];
 if (preg_match('/[^a-z A-Z0-9-]/', $item['link_title'])) {
    form_set_error('link_title', t('The title name may only consist of lowercase letters, numbers, and hyphens.'));
  }
  else
  {

  global $user;

  $node = node_form_submit_build_node($form, $form_state);
  $insert = empty($node->nid);
  node_save($node);
  $node_link = l(t('view'), 'node/'. $node->nid);
  $watchdog_args = array('@type' => $node->type, '%title' => $node->title);
  $t_args = array('@type' => node_get_types('name', $node), '%title' => $node->title);

  if ($insert) {
    watchdog('content', '@type: added %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link);
    drupal_set_message(t('@type %title has been created.', $t_args));
  }
  else {
    watchdog('content', '@type: updated %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link);
    drupal_set_message(t('@type %title has been updated.', $t_args));
  }
  if ($node->nid) {
    unset($form_state['rebuild']);
    $form_state['nid'] = $node->nid;
    $form_state['redirect'] = 'node/'. $node->nid;
  }
  else {
    // In the unlikely case something went wrong on save, the node will be
    // rebuilt and node form redisplayed the same way as in preview.
    drupal_set_message(t('The post could not be saved.'), 'error');
  }
  }
}

Thursday, September 13, 2012

Drupal menu system


The Drupal menu system was always much more than what the name suggests. It's not only used to display visible navigation menus but also to map Drupal paths to their callbacks with proper access checking. This second task is called dispatching. The likely rationale behind this; once you define a link to a page, you might want to define what happens when you click that link.
This eventually led to a very complex data structure which was stored as a serialized array in the database -- per user. Unserializing this on every non-cached page load uses tons of memory. Altering this either on build or run time needs dirty hacks.
Some misunderstandings about how access to an element applies to their children led to grave security holes with some contributed modules. This stresses the need for thought out, cleanly defined inheritance rules.
We have a new menu system in Drupal 6.x. The data is divided between two tables: {menu_router} and {menu_links}. The {menu_router} table is built based on the callbacks defined by implementations of hook_menu, and Drupal now looks in this table to determine access and the appropriate callback function when a site visitor tries to navigate to a particular path. Everything belonging to one path is one row in a database table, so the memory footprint is significantly smaller. The inheritance rules for access, etc. are cleanly laid out in the documentation. The {menu_links} table contains the links that are displayed in the Navigation and other menu blocks. Some of these items are derived automatically from {menu_router}, but others may be added by the site administrator using the menu module or other modules.
In hook_menu(), you define a menu array, which is an associative array. The keys are Drupal paths, the values are menu entries. One menu entry is again an associative array. A typical entry is:

<?php
  $items
['node/%node'] = array(
   
'title' => 'View',
   
'page callback' => 'node_page_view',
   
'page arguments' => array(1),
   
'access callback' => 'node_access',
   
'access arguments' => array('view', 1),
   
'type' => MENU_CALLBACK,
  );
?>
The menu builder collects these, applies inheritance rules and saves each entry in its row in the menu tables.
When you open a page, the system will generate the ancestors of the given path and ask the database for the menu entry of the ancestor that best fits this path. Then it calls the access callback to determine access. If it's given, it then hands over execution to the page callback.
The system determines that it has not found a path if no item can be retrieved from the database or if the node can not be loaded. Access denied is solely determined by the access callback/arguments.
The page callback function must return a non-NULL value, if any output is to be displayed in the browser for a given URL. If the function returns no value or a NULL value, Drupal will only render the content created by drupal_page_footer (which in turn is the content created by the hook_exit implementation of all the modules.)

Read More....

Sunday, September 2, 2012

install.php

The update system is used by modules to provide database updates which are run with update.php.
Implementations of these hooks should be placed in a mymodule.install file in the same directory as mymodule.module.

Functions & methods

NameDescription
hook_disablePerform necessary actions before module is disabled.
hook_enablePerform necessary actions after module is enabled.
hook_installInstall the current version of the database schema, and any other setup tasks.
hook_requirementsCheck installation requirements and do status reporting.
hook_schemaDefine the current version of the database schema.
hook_uninstallRemove any information that the module sets.
hook_update_last_removedReturn a number which is no longer available as hook_update_N().
hook_update_NPerform a single update.
Read More

hook_schema

A Drupal schema definition is an array structure representing one or more tables and their related keys and indexes. A schema is defined by hook_schema() which must live in your module's .install file.
By implementing hook_schema() and specifying the tables your module declares, you can easily create and drop these tables on all supported database engines. You don't have to deal with the different SQL dialects for table creation and alteration of the supported database engines.
See the Schema API documentation at http://drupal.org/node/146843 for details on hook_schema(), where database tables are defined.

Return value

A schema definition structure array. For each element of the array, the key is a table name and the value is a table structure definition.

Read More..

Saturday, September 1, 2012

OOPS (Object-oriented programming) Interview Questions


What is Polymorphisms?

Polymorphism means one interface and many forms. Polymorphism is a characteristics of being able to assign a different meaning or usage to something in different contexts specifically to allow an entity such as a variable, a function or an object to have more than one form.

There are two types of Polymorphism.
Compile time: function or operator overloading
Runtime: Inheritence & virtual functions

What is Abstract method?

Abstract method doesn't provide the implementation & forces the derived class to override the method.

What is Virtual method?

Virtual Method has implementation & provide the derived class with the option to override it.

Can Struct be inherited?

No, Struct can't be inherited as this is implicitly sealed.

What is Object?

Object is anything that is identifiable as a single material item.

What is Class?

A Class is the generic definition of what an object is a template.

The keyword class in C# indicates that we are going to define a new class (type of object)

What is Static field?

To indicate that a field should only be stored once no matter how many instance of the class we create.

What is Static Method?

It is possible to declare a method as Static provided that they don't attempt to access any instance data or other instance methods.

What is Inheritance?

It provides a convenient way to reuse existing fully tested code in different context thereby saving lot of coding.

Inheritance of classes in C# is always implementation Inheritance.

What is Virtual keyword?

This keyword indicates that a member can be overridden in a child class. It can be applied to methods, properties, indexes and events.

What is New modifiers?

The new modifiers hides a member of the base class. C# supports only hide by signature.

What is Abstract Class?

Abstract class is a class that can not be instantiated, it exists extensively for inheritance and it must be inherited. There are scenarios in which it is useful to define classes that is not intended to instantiate; because such classes normally are used as base-classes in inheritance hierarchies, we call such classes abstract classes.

Abstract classes cannot be used to instantiate objects; because abstract classes are incomplete, it may contain only definition of the properties or methods and derived classes that inherit this implements it's properties or methods.

Static, Value Types & interface doesn't support abstract modifiers. Static members cannot be abstract. Classes with abstract member must also be abstract.

What is Sealed modifiers?

Sealed types cannot be inherited & are concrete.
Sealed modifiers can also be applied to instance methods, properties, events & indexes. It can't be applied to static members.

Sealed members are allowed in sealed and non-sealed classes.

What is an Interface?

An interface is a contract & defines the requisite behavior of generalization of types.

An interface mandates a set of behavior, but not the implementation. Interface must be inherited. We can't create an instance of an interface.

An interface is an array of related function that must be implemented in derived type. Members of an interface are implicitly public & abstract.

An interface can inherit from another interface.

When to use Interface over abstract class?

Abstract Classes: Classes which cannot be instantiated. This means one cannot make a object of this class or in other way cannot create object by saying ClassAbs abs = new ClassAbs(); where ClassAbs is abstract class.
Abstract classes contains have one or more abstarct methods, ie method body only no implementation.
Interfaces: These are same as abstract classes only difference is we can only define method definition and no implementation.
When to use wot depends on various reasons. One being design choice.
One reason for using abstarct classes is we can code common
functionality and force our developer to use it. I can have a complete
class but I can still mark the class as abstract.
Developing by interface helps in object based communication.

What is pure virtual function?

When you define only function prototype in a base class without and do the complete implementation in derived class. This base class is called abstract class and client won’t able to instantiate an object using this base class.

A pure virtual function is a function that must be overridden in a derived class and need not be defined. A virtual function is declared to be "pure" using the curious "=0"
syntax:
class Base {
public:
void f1(); // not virtual
virtual void f2(); // virtual, not pure
virtual void f3() = 0; // pure virtual
};

only show translated menu items into current language (Drupal 8)

function MY_THEME_preprocess_menu(&$variables) {   if ($variables['menu_name'] == 'brancott-header-menu') {    $langu...