2

As a PHP developer familiar with MVC frameworks, I am having some difficulty figuring out Drupal.

I like the block setup. I am looking for some simple step-by-step guide to:

  1. Add a block with my own PHP code.
  2. Alter the html/php of other blocks.

Failing that, I would like to see some code which does these things.

Here is what I've been trying to do, more specifically:

  1. There is a button. When it is clicked a DB query is executed.
  2. Hide the "create new account" link on the login dialog. No account for you!
  • 1
    This question is really general. The broad answer to question 1 is to use hook_block. The broad answer to question 2 is to use hook_form_alter to remove the markup. – jhedstrom Apr 26 '11 at 1:32
  • I agree with jhedstrom; then, the asked questions seem unrelated to each other. – kiamlaluno Apr 26 '11 at 2:01
2

You are in fact asking four questions here.

  1. As jhedstrom said, you need to use the hook_block_info() / hook_block_view() hooks. A quick google search pointed to to this example: http://www.summasolutions.net/blogposts/how-create-basic-block-code-new-drupal-7

  2. You can use the hook_block_view_alter() or hook_block_view_MODULE_DELTA_alter() hooks.

  3. You can find detailed information about how to create a form in drupal in the quickstart guide. Note that this is for Drupal 6 but works the same way in Drupal 7 for the most part.

  4. This does not require any code at all. In fact, doing this with code is doing it the wrong way. Instead, you can disable account registrations by visitors at Configuration > Account settings, set "Who can register accounts?" to Administrators only.

  • 3
    Since you're learning Drupal APIs don't forget the Examples project, drupal.org/project/examples, which has working examples (for D7 and D6) of all of the above. – rfay Apr 26 '11 at 4:43
  • This is also an excellent answer. I had tried hook_block_view_MODULE_DELTA_alter() but I didn't know about the cache, hence my frustration. – JIStone Apr 26 '11 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.