Needs work
Project:
Block API
Version:
7.x-1.x-dev
Component:
Code
Priority:
Critical
Category:
Task
Assigned:
Issue tags:
Reporter:
Created:
7 Sep 2010 at 09:23 UTC
Updated:
20 May 2011 at 17:21 UTC
Jump to comment: Most recent file
I know it would make the most sense for me to integrate this module with menu_block in a 6.x branch, but I've got a 7.x module that needs this ASAP.
So I'm going to try porting this to Drupal 7 and playing with the module’s API there.
| Comment | File | Size | Author |
|---|---|---|---|
| #47 | block_api-HEAD.html.47.patch | 3.66 KB | sun |
| #44 | block_api-HEAD.module.44.patch | 6.57 KB | sun |
| #43 | block_api-HEAD.module.43.patch | 6.04 KB | sun |
| #42 | block_api-HEAD.module.42.patch | 5.36 KB | sun |
| #41 | block_api-tests.patch | 1.62 KB | jamestombs |
Comments
Comment #1
jamestombs commentedHi John, I have a D7 version but have had trouble with CVS and have been unable to get it on to d.o.
Due to name changes in D7 I have had to make quite a few changes to the function names which I duplicated to the D6 module, but again have had trouble with CVS.
Attached are Zip files containing the 2 different versions, and I really need to get my head around CVS but am afraid I will bugger things up.
Comment #2
jamestombs commentedBoth latest D6 and D7 releases now on CVS.
Comment #4
sunA couple of issues:
1) The HEAD branch contains D6 code.
2) There is also a DRUPAL-7--1 branch, but it is empty. (also, HEAD should be used for code compatible with Drupal core HEAD; so this is more or less correct, but having an empty branch is kinda confusing)
3) The official 7.0-beta1 release contains D6 code. (!) It should be unpublished and/or marked as unsupported.
4) There is no DRUPAL-6--1 branch for the D6 code yet, so HEAD needs to be branched into DRUPAL-6--1 first, before replacing HEAD with D7 code.
Comment #5
jamestombs commentedI really need to get my head round CVS.
Comment #6
sunI'm available in IRC, if you need help. :)
Comment #7
jamestombs commentedThanks for your help sun, think I am getting it.
Attached is a patch with the changes to hooks to use hook_block_api_info rather than hook_block_api_block_types and hook_block_api_view instead of hook_block_api_display.
Also converted files from DOS to Unix so it is bigger than usual.
Comment #8
jamestombs commentedAttempt #2 at uploading patch
Comment #9
jamestombs commentedPatch again without the dos2unix bits
Comment #10
sunPatch looks good. However, I have some remarks we should tackle in a follow-up:
I do not understand
1) Why these API functions are private?
2) Why there is a separate API function for retrieving the description?
Powered by Dreditor.
Comment #11
jamestombs commentedI have no idea, it probably made sense to me at the time.
I don't see any reason why the following 3 functions can't be combined:
_block_api_get_type(), _block_api_get_block_type_descriptions(), _block_api_get_types()
To have something like:
Comment #12
sunLet's commit the current patch to HEAD first? Afterwards, I'll try to review the entire module's code + perhaps come back with a patch ;)
Comment #13
jamestombs commentedHEAD updated
Comment #14
sunWe need #994870: Custom #type machine_name 'exists' callbacks cannot access other form elements/values for Block API, so please help to get that in.
Comment #15
jamestombs commentedNot sure I completely understand the need for it, although by the looks of it, it wouldn't do any harm anyway and would likely help some people with their validation of machine names in some cases.
Although it has brought up a point where you mentioned the "joined" machine name. I don't think this is necessary any more as the blocks are defined in the database as belonging to block_api and not the other module (this is handled in the block_api table) where as originally the block belonged to the original module like menu_block works.
So the "block_api_" prefix on the machine name/delta could be removed with no ill effects.
Comment #16
sunFirst pass.
Some considerations and topics we should discuss:
A block type is what modules register via hook_block_api_info(). A block instance is a block of a certain type.
By implementing and integrating with D7's Entity API and Field API, there's *lots of* stuff we will get *for free*. (Such as: fieldable blocks)
Comment #17
jamestombs commentedAttached is an updated patch of your patch with a few bug fixes.
I'm just thinking if #2 is in the scope of the project i.e. is it needed in this module or better placed in a sub module to allow the user to create block types to appear in the module block creation list in a UI like they create content types at the moment but are still able to define block types within their modules as they currently can do with block api.
Regarding #3, block_type is needed as modules can define more than 1 block type and works in the same fashion as the core node module. machine_name and delta are the same thing (although delta prepends the entered machine_name with 'block_api_' (although I don't think this is necessary)
Comment #18
sunCoolio, thanks!
So as of now, I understand that
block_api_MACHINENAME.machine_nameis stored as a reference in {block_api}, but withoutblock_api_prefix.$block_type, is only stored as a passive reference in {block_api}.html. There is no module name prefix (e.g.,html_block_html) that would ensure that block types of multiple modules are unique. Only the user-entered machine name of block type instances is unique.foo_barblock, regardless of block type. It sounds acceptable to have this "limitation".Thus, it looks like we should
block_api_prefix from machine names, so{block_api}.machine_name == {block}.delta.html).I also badly want to clean up, resp. rename, the {block_api} table column names in a follow-up patch.
Powered by Dreditor.
Comment #19
sunImplements most of #18.
Comment #20
sunA couple of fixes after manual testing.
Comment #21
sunFixed block deletion (and also updated code and strings to latest Block module code in Drupal HEAD).
Comment #22
sunFurther minor adjustments. I think this second follow-up is in itself self-contained and ready to fly (commit) now. We should continue with remaining tasks in this issue though.
Also, marking this RTBC reminds me... I'm going to commit the usual baseline of module and testing files (for automated unit tests), if you're OK with that?
Comment #23
jamestombs commentedHappy to remove block_api from delta and that makes sense.
The type has to be stored so that the module that defines the block type can save/delete/show form/view the block. As far as I can see, it doesn't matter if the block type is unique, as long as it is unique per module which it has to be with associative arrays.
Just found a small bug in D7 machine_name which I will submit, but everything else with the latest patch in #21 works fine.
Comment #24
jamestombs commentedYeah that is fine.
Also changing status (was editing while you posted).
Comment #25
sunheya :) can you hop into IRC? :)
Comment #26
sunThanks! Committed to HEAD: http://drupal.org/cvs?commit=463276
Comment #27
sunStill need to complete the db updates, but attached patch reworks the entire remaining CRUD functionality.
Comment #28
sunCompleted the db schema changes. Renamed 'block_type' to just 'type'. Also considered to rename 'admin_title' to 'info' to be consistent with Block module's {block_custom} schema/terminology, but then re-considered, because 'admin_title' is way more descriptive than 'info'.
Comment #29
sunNow with tests...
42 passes, 0 fails, 0 exceptions, and 12 debug messages
YAY! :)
Comment #30
sunOopsie, still need to document these.
However, leaving those two @todos for later, as I'm not sure how those constants are supposed to work currently.
Powered by Dreditor.
Comment #31
sunAdded those CRUD API docs. (We're still missing Block API docs => leaving that to the follow-up patch that will change the hook names).
Comment #32
sunIt's possible that I won't be able to come back to block_api module very soon, so I went ahead and committed those CRUD API improvements + tests now, in order to try to continue with as many improvements as possible today.
Comment #33
sunFull core entity system/API integration.
Comment #34
sunAs tests still pass, committed that one, too.
Comment #35
sunResolving some of the last remaining @todos.
Comment #36
sunChanged the hook names (more or less) as discussed. Also added documentation for the hooks.
Didn't go with the TYPE as suffix, because I figured that we might want to provide a "full" Form API integration at some point in the future; i.e., hook_form(), hook_form_validate(), hook_form_submit().
Comment #37
jamestombs commentedSame as 36 with a few typos amended in the html_block module file.
Comment #38
sunThanks for reviewing, and testing! Committed to HEAD.
Attached patch is most likely going to be the last from me today. However, I really have a positive feeling about the current (revamped) API and state of the module.
JohnAlbin should be easily able to integrate with Block API now.
Comment #39
sunAlso fixed missing phpDocs in block_api.install.
Comment #40
sunAdded one small change to block_api_block_info() to additionally output the title of block type of a block instance. While doing so, I realized that hook_block_info() allows modules to set additional Block module properties and we don't support those currently.
Comment #41
jamestombs commentedUpdate to test when module defining block type is disabled.
Comment #42
sunMerged the patches and improved the added test.
Comment #43
sunThis one fixes the fatal error revealed via tests when a block type module is disabled.
Comment #44
sunSeparated the module system integration test into a new test case class. Note: You need to flush caches (class registry) in order to see and run the new test case in SimpleTest.
Comment #45
sunAnd #44 passed tests. :)
Comment #46
sunComment #47
sunSo my last worry was the html_block sub-module, which is technically outside of the project's namespace. Attached patch moves that simple example into the API docs and removes the sub-module.
Comment #48
sunThe last remaining problem to resolve is the internal module/type clash in block_api_get_info():
As of now, the block type info is used internally in two locations only. It might even be possible to key the block info by module AND type; i.e., $types[$module][$type] - and perhaps that would also be most sane way to resolve the issue.
@jamestamr: Can you take this on?
Comment #49
jamestombs commentedYep, will look in to it.
Comment #50
sun@jamestamr: Any updates?
Comment #51
jamestombs commented@sun, no, I have been super busy on some other project work. Hope to get on to this over the holiday break.
Comment #52
sunWe should try to resolve that tiny last bit in #48 as soon as possible (this week[end]?), so we can create an official release for D7.
Comment #53
jamestombs commentedI unfortunately haven't had a chance to look at it with my work load, but will try to get on IRC tomorrow and go through it.
Comment #54
jamestombs commentedJust had a quick play.
$types[$module][$type] = $info;Won't work, as block_api_create_form() will still get the type by itself so name clashes won't will still clash on the add module block form (once you have added another foreach to take in to account the new hierarchy).
$types[$module .'_'. $type] = $info;Breaks the hook_block_api_TYPE_xxxx() hooks, they would need to be hook_block_api_hook_TYPE_xxxx().
If we did this, we could change the hooks to hook_TYPE_block_api_xxxx(), but there is a chance of a name clash such as:
Module name: xxx
Block type name: yyy_zzz
Resulting view hook: xxx_yyy_zzz_block_api_view()
Module name: xxx_yyy
Block type name: zzz
Resulting view hook: xxx_yyy_zzz_block_api_view()
Comment #55
klonos