Hi Fago,
Content is going to be viewed, is a bit tricky if I want to do a page redirect from a certain, since it will be invoked also when the node is shown as teaser or as a result in the 'Search'.

A solution to do that can be adding an arrgument to check how is the content being viewd (i.e. full view, teaser). In the future other modules can add more options, so WF can now when a content appears as Views:bonous grid.

1. import WF
2. search for a words that will result with search showing a teaser of story nodes.

array (
  'cfg_14' => 
  array (
    '#type' => 'configuration',
    '#altered' => false,
    '#event' => 'node_view',
    '#label' => 'Direct from Story',
    '#active' => 1,
    '#module' => 'workflow-ng',
    0 => 
    array (
      '#type' => 'condition',
      '#name' => 'workflow_ng_condition_content_is_type',
      '#label' => 'type=story?',
      '#settings' => 
      array (
        'type' => 
        array (
          'story' => 'story',
        ),
      ),
      '#argument map' => 
      array (
        'node' => 'node',
      ),
    ),
    1 => 
    array (
      '#type' => 'condition',
      '#name' => 'workflow_ng_condition_user_hasrole',
      '#negate' => 1,
      '#weight' => '1',
      '#settings' => 
      array (
        'roles' => 
        array (
          0 => 3,
        ),
        'operation' => 'OR',
      ),
    ),
    2 => 
    array (
      '#type' => 'action',
      '#name' => 'workflow_ng_action_drupal_message',
      '#settings' => 
      array (
        'message' => 'WF should check if Full or non-full view',
        'used arguments' => 
        array (
        ),
        'error' => 0,
      ),
    ),
    '#description' => NULL,
    '#attributes' => 
    array (
    ),
    '#required' => false,
    '#tree' => false,
    '#parents' => 
    array (
    ),
    '#recursion' => false,
    '#fixed' => false,
    '#execute' => 'workflow_ng_execute_configuration',
    '#process' => 
    array (
      'workflow_ng_ui_prepare_configuration' => 
      array (
      ),
    ),
    '#_defaults_applied' => true,
    '#name' => 'cfg_14',
  ),
)

Comments

amitaibu’s picture

sorry for all the misspelling, it's late at night ;)

fago’s picture

sounds useful, but......

* drupal currently doesn't support more view modes, there is only teaser, page on/off
* even supporting only teaser and page would be a bit tricky. Probably best would be to add a new entity type to workflow-ng, called "boolean", add the existing $teaser and $page boolean to the event info and finally add a condition to check a boolean.

amitaibu’s picture

Fago,
I'd like to give a shot on this task. Some 'tips' ? :)

fago’s picture

hm, only this from above
"Probably best would be to add a new entity type to workflow-ng, called "boolean", add the existing $teaser and $page boolean to the event info and finally add a condition to check a boolean."

amitaibu’s picture

Fago,

UPDATE: Ok I think I got your point about the elements.

Might be because I'm a bit confused about the entity, but isn't it good/ possible to pass the $page in the hook_nodeapi, as this is related to nodes?

function node_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) 
...
workflow_ng_invoke_event('node_'. $op, array('node' => &$node, 'page' => $page)); 

In other words, what is the advantage/ need for a new entity?

amitaibu’s picture

Status: Active » Needs review
StatusFileSize
new3.23 KB

Patch attached.

fago’s picture

Status: Needs review » Needs work

You would also do it that way with a new entity: workflow_ng_invoke_event('node_'. $op, array('node' => &$node, 'page' => $page));

-> The new entity has the advantage that you can write specific actions / conditions for it.

* workflow_ng_invoke_event('node_'. $op, array('node' => &$node, 'page' => $page));
This is good, but only for the operation 'view'. (Read docs about hook_nodeapi)

* @token integration:
+ else if ($entity_type == 'boolean') {
+ $tokens['node']['page'] = t('Whether the node appears as a page. (@yes/@no)', array('@yes' => t('yes'), '@no' => t('no')));
+ $tokens['node']['teaser'] = t('Whether the node appears as a teaser. (@yes/@no)', array('@yes' => t('yes'), '@no' => t('no')));
+ }

This says, add for each boolean the tokens 'page' and 'teaser', which clearly makes no sense. You could only add one general "on/off" token for the entity boolean - but I don't know if that is very useful.
I suggest to add a condition, which allows to check a boolean in the way if ($page) do ... -> I'd add this to workflow-ng's conditions/actions. Then users can use it to check the existing boolean values.

amitaibu’s picture

Question: how to expose the page and teaser as token only when the event is related to node view?

We can't do it when the entity is node as it's not only for view.

amitaibu’s picture

Status: Needs work » Needs review
StatusFileSize
new34.83 KB

I'm not sure I'm fully getting it. Just let me know if I'm on the right track:
* I've add a condition for Boolean.
* In case a page is viewed I pass also the $page and $teaser.

Question from #8 still remains..

fago’s picture

hm, I think something went wrong with your patch. It removes the system.inc file and adds it back again - so I can't read your changes. Please re-roll it.

#8: You don't need to. This is covered by workflow-ng for you - as it will only list token help for entities that are available.

* I've add a condition for Boolean.
* In case a page is viewed I pass also the $page and $teaser.

That sounds fine :)

fago’s picture

Status: Needs review » Needs work
amitaibu’s picture

One question that I'm still not getting:
I need to declare the page and teaser tokens, but as you said workflow_ng_token_list isn't the right place. So how do I declare them for Boolean entity only when event 'Page is going to be viewed'?

btw, Condition to check boolean - Wouldn't you prefer keeping this check through the Textual comparison, like you did for [node:state] for example?

fago’s picture

you need to declare them as workflow-ng arguments, then you pass it to event. so workflow-ng knows that these are arguments of the type boolean, so it applies the token of "boolean" to it and allows you to use the condition, which you have written for booleans.

You need to write the token integration, for the entity type "boolean", not for each instance of it.

amitaibu’s picture

Status: Needs work » Needs review
StatusFileSize
new11.23 KB
new2.85 KB

I've been able to pass it through the arguments - Is this acceptable by you, or you'd like it as a token (and if so, where/ what function do I need to integrate Boolean entity? I'm still missing this part)

mooffie’s picture

Component: Code » Miscellaneous
Status: Needs review » Needs work

Do we really need this boolean entity? I think not, because:

  1. A 'boolean' may not provide for the future, where Drupal may have more rendering modes for a node (which is already the case for D6).
  2. We can simply store the redering type on the node object itself. E.g. $node->_wfng_teaser = $teaser etc. As far as I can see, it's allowed to "ruin" the node at this stage. In fact, at this stage the node is already "ruined" by node_build_content() and node_prepare(). BTW, for this reason the administrator should not execute an action which saves a node which is being viewed.
fago’s picture

Component: Miscellaneous » Module Integration
Status: Needs work » Needs review

hm, in d6 the parameters of hook_nodeapi op=view are the same as in d5. So a boolean fits, even in d6.

@2: indeed. However saving should be ok, as modules usually only save their own values of $node. However I'd consider "polluting" $node as bad style.

I need to test the patch, however it already looks good to me.

mooffie’s picture

StatusFileSize
new6.47 KB

Here's a different method to solve this. See attached patch. (Hello, Amitai! I wasn't online so I didn't read fago's last message where he said he liked your patch ;-) Your patch isn't _bad_, and in fact I probably wouldn't have bothered writing my own solution if I knew of his opinion ;-) )

So,

I've introduced here a new entity, 'rendered_node'. This will allow us a new class of conditions and actions that work on such entities. I've supplied a sample action: "Overwrite rendition of content with typed-in HTML." This action let us implement the 'premium' module all in Workflow-ng!

But there's another nice action that can be written for such entities: "Render a previous revision." This will be useful for those asking "If somebody edits his profile node, I want all users to see the old version till I approve the changes."

(But feel free to scrap this patch.)

fago’s picture

thanks, for this interesting ideas :)

However, I don't think that "rendered_node' is a good idea, as this won't allow using 'node' conditions, actions any more. For this we would need type inheritance ;). So let's go with the boolean way. Does amitaibu's patch work for you mooffie?

Regarding approve changes: I think for this case the revision moderation module fits better. (check http://drupal.org/node/175414 for even scheduled publishing of revisions :)

However, the idea of altering the showed content of a node at runtime is nice. It could be already possible with the current system. Write an action that alters the printed html of a node - but don't return the node so it won't be saved but take the node by reference. So the changes should apply to the node without having workflow-ng saving the node for nothing.

regarding "// At this stage $node is tainted;"
I don't think it's really tainted. Saving a node in this state should work fine, doesn't it?
Yes there are some additional properties in the node object, but no module should go and save it.

mooffie’s picture

[...] let's go with the boolean way. Does amitaibu's patch work for you mooffie?

OK, you're the judge here :-)
I've just downloaded Amitai's patch and I'll give it an inspection today or tomorrow.

(The following is my reply to some other points you raised, but you don't need to reply to it as it seems we'll not be going the 'rendered_node' route.)

regarding "// At this stage $node is tainted;"
I don't think it's really tainted. Saving a node in this state should work fine, doesn't it?

I don't think so. Before hook_nodeapi('view') is called, the following operations take place:

$node->body = str_replace('<!--break-->', '', $node->body);
...
$node->body = check_markup(...);

So we don't want $node->body to be saved at this stage. We also don't want to send this node via email... because the next node_view() will process this botched $node->body.

OTOH, I wonder if anybody would really find a need to carry on this sort of actions on a node in a 'node_view' event. Seems unlikely.

Regarding approve changes: I think for this case the revision moderation module fits better. (check http://drupal.org/node/175414 for even scheduled publishing of revisions :)

Oh, that looks nice. I should give it a try soon. Yes, maybe it makes my proposed "render a previous revision" action unneeded.

I don't think that "rendered_node' is a good idea, as this won't allow using 'node' conditions, actions any more.

'node' conditions and actions are still allowed, becuase besides 'rendered_node' there's the usual 'node' argument.

'rendered_node' is in addition to 'node'. It doesn't replace it.

[...] the idea of altering the showed content of a node at runtime is nice. It could be already possible with the current system.

Yes, it's already possible with the current system, but:

The 'rendered_node' entity gives us semantics, too. If we don't have this entity, all the conditions/actions that can operate only on rendered nodes will be listed, in the drop-downs, together with actions that don't. This new entity let us have some order.

This 'rendered_node' entity wasn't intruduced just to solve some technical problem. It was introduced to allow a new class of actions and conditions: those that have meaning only for rendered content. But perhaps there are only very few such conditions/actions. Perhaps there are only one or two. So it might very well be that you're right and that this entity isn't all that needed. OTOH, this 'rendered_node' solution looked elegant to me, and Elegant Things tend to be the Right Things.

But let's move forward, I'll test the 'boolean' patch very soon.

mooffie’s picture

Version: 5.x-1.x-dev » 5.x-2.x-dev

Does amitaibu's patch work for you mooffie?

Yes, I can confirm that it works.

Currently it doesn't expose the boolean entities as tokens. But doing so in the way we're doing it with [status] and [promote] would fail in localized environments.

(The patch does not apply cleanly. I'm not uploading a clean patch because the localization issue is yet to be settled.)

fago’s picture

hm, but the localization issue doesn't affect this, as it doesn't use tokens?

mooffie’s picture

hm, but the localization issue doesn't affect this, as it doesn't use tokens?

That's true. Amitai's patch doesn't use tokens, and can be applied as-is. It works.

The two boolean entities (one for 'teaser', one for 'page') can be examined by the admin using a condition --workflow_ng_condition_token_boolean-- that Amitai provided.

That's perfectly OK.

It's just that earlier in the discussion you asked to expose these entities as tokens. Probably your intention was that the admin would examine these entities via tokens, not via a WF condition. Both ways are valid.

(You want me to expose these entities as tokens? And, if so, you want me to also remove the condition, 'workflow_ng_condition_token_boolean'?)

fago’s picture

Component: Module Integration » Wng Module Integration
Status: Needs review » Fixed

sry for letting this lie so long. I prefer the solution as boolean entity, so I've taken amitaibu's patch, adapted it to the current 2.x codebase and committed it :)

thanks!

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

mooffie’s picture

Status: Closed (fixed) » Active

You know, I feel it was a miss not to pick my solution (comment #17).

A reminder: I introduced a 'rendered_node' entity. I felt this solution is so elegant and powerful that I didn't bother to glorify it _too_ much. I think I erred here.

I'm re-opening this issue just so that my gloom thoughts appear on your radar ;-) Feel free to close it. I stumbled upon a support question that could have been solved by a 'rendered_node' entity.

fago’s picture

Status: Active » Fixed

that's with the current solution possible too - so there is no cause for your solution (which result in the "node" actions not to work)

-> one can write actions like
my_module_my_action_filter(&$node) {
change($node)
}

and it won't be saved by workflow-ng, as you haven't returned array('node' => $node)

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.