[development] need a standard for contrib node build_mode constants

Moshe Weitzman weitzman at tejasa.com
Mon May 18 19:16:44 UTC 2009


Peter clarified in IRC that his timestamp proposal for for D6 and that
we should use strings for D7. And yes, we need a patch at
http://drupal.org/node/409750

On Mon, May 18, 2009 at 3:13 PM, larry at garfieldtech.com
<larry at garfieldtech.com> wrote:
> Peter's suggestion may work for D6, but for D7, I refer people to Eaton's
> "How to make good APIs" session from DCDC.  Digest version: If you expect
> people to extend your list of flags/constants/modes, for the love of god use
> strings, not ints.  Ints WILL break.  Don't be stupid, use strings.
>
> So it sounds like if we expect people to extend the build modes from
> contrib, then core should switch from ints to strings anyway.  Who wants to
> roll the patch? :-)
>
> --Larry Garfield
>
> Peter Wolanin wrote:
>>
>> The reason I was suggesting sticking with ints is that strings are
>> cast to int 0 during comparison:
>>
>> php -r"var_dump('cck' == 0);"
>>
>> bool(true)
>>
>> And core has code like:
>>
>> modules/upload/upload.module:363:  if ($node->build_mode ==
>> NODE_BUILD_RSS) {
>>
>> modules/book/book.module:710:    if (!empty($node->book['bid']) &&
>> $node->build_mode == NODE_BUILD_NORMAL) {
>>
>> So if CCK is using ints, that's a potentially serious bug - 0 is
>> NODE_BUILD_NORMAL, so I think any string build modes will basically
>> end up being this mode.
>>
>> -Peter
>>
>> On Sat, May 16, 2009 at 11:50 PM, Earl Miles <merlin at logrus.com> wrote:
>>>
>>> Peter Wolanin wrote:
>>>>
>>>> When doing some cleanup of my Modr8 module, I wanted to define a new
>>>> build_mode for use by
>>>> http://api.drupal.org/api/function/node_build_content/6
>>>
>>> I believe there is no need to stick with ints; CCK uses this and I think
>>> it's using strings.
>>>
>


More information about the development mailing list