Drupal

What Path is the current page in Drupal 7

When you are writing code that will fit into a page, how do you know the page you are on. There are two (2) paths. The Real path that Drupal uses node/147 Which can be found this function. current_path(); And the Aliased path that you are actually using. PathAuto will do this for you or you might manually set a path. article/your-title-here Which can be found this function. request_path(); This last value can also be…

Continue reading

Drupal

Write a Custom Panel for Page Manager in Drupal 7

Page Manager allows you to build up a “page” with smaller “panels”, such that you can add fields, blocks and views into different layouts. But how do you write your own custom panel? Page Manager is a part of the Chaos Tools module. Register a Plugin Directory Create this function in your modules .module file. This simply tells cTools where to look for additional plugins. Remember that Chaos Tools uses the term “Content Types” differently…

Continue reading

Drupal

Programmically Add/Edit Nodes in Drupal 7

There are quite a few references out there for how to programmically add and edit nodes – but I think I need my own. Lets first start with someone elses work that covers all of the basics. The steps for programmatically creating a node are: Create a PHP object representing the node data Save the object using the node_save() function While the mechanics are simple, there is an important responsibility involved. The Drupal work flow…

Continue reading

Drupal

Saving Adhoc Data in Drupal 7

If you want to play with nodes, taxomony and comments, there is a process and set of functions that you should use to do that. If you just want to drop some adhoc data into a table, then you can use the db_insert() function. Here is an example. $data[“field1”] = “value1”; $data[“field2”] = 123.45; etc… $result = db_insert(‘tablename’) -> fields($data) -> execute(); If you get it wrong, you will get a PDO Error – which…

Continue reading

Drupal

Getting CodeFilter to work in WYSIWYG

CodeFilter is a Drupal module that highlights source , [ ?php ? ], < % % >, and [ % % ] to prevent other filters from acting on them. */ $text = preg_replace_callback(‘@(.+?)@s’, ‘_codefilter_escape_code_tag_callback’, $text); $text = preg_replace_callback(‘@\(.+?)\@s’, ‘_codefilter_escape_code_tag_callback’, $text); $text = preg_replace_callback(‘@[\[]@s’, ‘_codefilter_escape_php_tag_callback’, $text); $text = preg_replace_callback(‘@(\[|\)@s’, ‘_codefilter_escape_php_tag_callback3’, $text); return $text; } and adding a new function function _codefilter_escape_php_tag_callback3($matches) { return codefilter_escape($matches[3], ‘php’); } 3. Remove the wrapper I don’t want to have…

Continue reading

Drupal

Embed YouTube in a Drupal 7 Page

If you want to embed adhoc YouTube videos into you Drupal 7 pages, you have several option. One option is to use the “Embed” option on the YouTube page. This will create an iFrame HTML code that you can paste into your page. You will need to turn off the WYSIWYG filter first to embed raw HTML – and then the video will appear as white block while editing. Another option is to use the…

Continue reading

Drupal

Creating an AJAX Link in Drupal

What I want is a standard link, that when clicked does things. I want to do some server side processing, that returns a result, that can be processed locally (aka in the browser). For example, click an “active” icon for a product. The product is made inactive and the “active” icon is replaced with an “inactive” icon. Step 1: The link In this example I am creating two links An AJAX based link. It will…

Continue reading