Someone please explain this to me
Permalink
I am doing some dirty work with hard coding a block into a page type. (details:http://www.concrete5.org/community/forums/customizing_c5/callload-a... I am at the point, where everything almost works. In my block's view, I have a call to BlockView :: action(). Unfortunatelly the call fails, because inside the action method, the attribute $this->block is not an object. Trying to find out how and where it is set, I stumbled upon the following code (BlockView :: render()):
I simply do not understand what is goind on here. First things first: getBlockFileName() is a method of BlockType but the call is the branch when $obj is NOT an instance of BlockType. What??? Secondly. How can $obj be anything else, that a BlockType? Thirdly: if it is in fact an instance of BlockType, why isn't $this->block set to that value? Could someone give me some insight on what is going on here? Thanks!
if ($obj instanceof BlockType) { $bt = $obj; $base = $obj->getBlockTypePath(); } else { $bFilename = $obj->getBlockFilename(); $b = $obj; $base = $b->getBlockPath(); $this->block = $b; $this->c = $b->getBlockCollectionObject(); if ($bFilename == '' && is_object($this->area)) { $customAreaTemplates = $this->area->getCustomTemplates(); $btHandle = $b->getBlockTypeHandle(); if (isset($customAreaTemplates[$btHandle])) { $bFilename = $customAreaTemplates[$btHandle]; }
Viewing 15 lines of 17 lines. View entire code block.
I simply do not understand what is goind on here. First things first: getBlockFileName() is a method of BlockType but the call is the branch when $obj is NOT an instance of BlockType. What??? Secondly. How can $obj be anything else, that a BlockType? Thirdly: if it is in fact an instance of BlockType, why isn't $this->block set to that value? Could someone give me some insight on what is going on here? Thanks!
Hey John! A good day to you! Thanks for your tip. Unfortunatelly, I might have failed to explain my problem properly. I have a form in my block's view.php and I want to print out an appropriate value into the action attribute with $this->action(), which call in this case means BlockView :: action.
The problem is, that this method works only if $this->block is an object type. But $this->block is set only once, inside BlockView :: render (see the cited code above), and only in the case of being called by a block object and not in the case of hard coded blocks, which call BlockView :: render as BlockType objects.
I'm not trying to call a method of the controller, I'm trying to print out the appropriate value for a form action attribute. The processing will be done by a block controller's action though.
I hope all this makes some sense! Thanks!
The problem is, that this method works only if $this->block is an object type. But $this->block is set only once, inside BlockView :: render (see the cited code above), and only in the case of being called by a block object and not in the case of hard coded blocks, which call BlockView :: render as BlockType objects.
I'm not trying to call a method of the controller, I'm trying to print out the appropriate value for a form action attribute. The processing will be done by a block controller's action though.
I hope all this makes some sense! Thanks!
I've tried setting $this->block the same value if the render is called by a BlockType object to see if this might only be a bug, but errors propagate such that I have the impression, that it is not intented to solve my problem this way. Do you know a better way on how to hardcode blocks with custom templates and forms, so that they would cooperate nicely with C5?
In a block view, you can get the action by simply calling:
However, there are limitations on how you can call the block controller action. I don't know if it will work as the submit action of a form in the same way that it would for a single page view to controller.
$action_link = $this->action('action_method_name');
However, there are limitations on how you can call the block controller action. I don't know if it will work as the submit action of a form in the same way that it would for a single page view to controller.
Actually, this does not work. That is why I came to the forums. :) This call works only if the object calling BlockView :: render is an instance of Block, but does not producde output if it is of BlockType, which is my case of a hardcoded block. Anyway, because of all this misery, I figured, that this kind of solution (i.e.: hard coding of blocks) might be bad practice, and that is why it is not well supported, so I decided to solve the original problem another way, without hard coding of blocks. Thanks anyway!
If you are making an ajax call, it gets more complex because the block may not actually exist. There are some examples (a little bit dated) in the Ajax Lessons addon and associated howto.