Override block

Permalink
Hi,

I want to add display options on a block.
Example: block file, add checkbox author. If the checkbox is selected, I display the author of the file.

I wish to be able to overload the edit view of the block file (controller.php and composer.php) and manage this option in the file "view.php".

Is it possible to overload the existing block? (if so how?) or I have to create a new block ?

Thank you for your help and your answers

GuillaumeAgresta
 
hutman replied on at Permalink Reply
hutman
If you copy the controller.php and composer.php into the application/blocks/BLOCK_NAME/ directory you can override them and add options (you will need to move the db.xml too if you're adding a field). Once you have made your updates you will then need to go into the Dashboard -> Stacks & Blocks -> Block Types and refresh that block.

You can not control the edit screen from the view however, if that's what you were planning. But once you have updated the other files you should be able to use the variable you created in the view.
GuillaumeAgresta replied on at Permalink Reply
GuillaumeAgresta
OK thanks for your answer. I will try this.
GuillaumeAgresta replied on at Permalink Reply
GuillaumeAgresta
Hi,

If you can not edit the edit view, what is the best way to provide display options?

- If I created a template by style of display, it will make many templates to manage the different possibilities (example: template with the name of the author, template with the date of creation of the file, template with the name of the author author and creation date of the file ...)

- If I create a new block file, I lose the interest of the overload on product updates.

- Other ?
hutman replied on at Permalink Reply
hutman
You can change the edit.php (and the add.php) you just can't change the edit screens with the view.php.
GuillaumeAgresta replied on at Permalink Reply
GuillaumeAgresta
Sorry,
I do not understand anything, here is what I tried:

1- Creating the "file" folder in ".\Packages\My_name_Package\blocks\"
2- Copy and paste files "add.php" and "edit.php" in the folder: ".\Packages\My_name_Package\blocks\file\"
3- In these files "add.php" and "edit.php", I added a label "test"
<div>Test</div>

4- I did a refresh in the Dashboard -> Stacks & Blocks -> Block Types -> File
5- On the site, I added a block "file" but I do not see my label "test" in the window.

I do not understand your remark:
"...can't change the edit screends with the view.php"

You want to talk about the view of the add/edit window or the rendering view on the website ?
On the second point, it is possible to overload the rendering view on the website via templates

What did I miss?
hutman replied on at Permalink Reply
hutman
Ok, first you can't override blocks like that in a package without a bunch of code, so start easy and copy the files from /concrete/blocks/block_name/ to the application/blocks/block_name/ directory - if this directory doesn't exist create it. I am assuming you have an application directory - if you don't have an application directory you are probably using 5.6 and that requires some different changes.

Second, if you're going to add a new field you have to copy the controller.php, add.php, edit.php, db.xml, and view.php. Once you have done that make sure to update the namespace in the controller.php

Third, you have to change the db.xml in order to add a new field - after you have done this refresh the block in the dashboard.

Last, make sure your caches are turned OFF, all of them. Otherwise you won't see any of your changes without clearing the cache every time you make a change (this should really be first).
GuillaumeAgresta replied on at Permalink Reply
GuillaumeAgresta
Thank you very much for your response.

I performed a test by copying the files in '.\Application\blocks\faq' and at that level, it works, I see my label "test".

Following your remark, I realize that I have never communicated to you the version of my concrete5, I am in 8.2.1.

Now how can I put it to the override of my package ?
To understand all, I currently have a package that includes a theme but also a new block and templates for existing blocks.

Sorry for my poor English
hutman replied on at Permalink Reply
hutman
I think you have to use this for the controller:

public function on_start() {
   $objPkg = Loader::package($this->pkgHandle);
   $objEnv = Environment::get();
   $objEnv->overrideCoreByPackage('blocks/block_name/controller.php', $objPkg);
}


I don't know if you can override the db.xml to add your new field this way though.