How to customise SecurimageController in Concrete5.7

Permalink
Hello,

I have a system Captcha in my contact form which works fine.

In Concrete5.6, you just copy the core controller and modify it. Following this:https://github.com/concrete5/concrete5/issues/2088... - it all works fine. But I want to do that as part of my package. So, if I, instead of aplication/src/Captcha/SecurimageController.php, make it packages/my_package/src/Captcha/SecurimageController.php - nothing changes, the original system controller is used.

How can I customise the system controller in Concrete5.7? Here are my files:

packages/my_package/src/Captcha/SecurimageController.php:
<?php
namespace Packages\MyPackage\Src\Captcha;
use Securimage;
use Securimage_Color;
class SecurimageController extends \Concrete\Core\Captcha\SecurimageController
{
    protected $securimage;
    public function __construct()
    {
   $this->securimage = new Securimage();
   $this->securimage->image_width = 237;
   $this->securimage->image_height = 60;
   $this->securimage->image_bg_color = new Securimage_Color('#F0F0F0');
   $this->securimage->line_color = new Securimage_Color('#333333');
   $this->securimage->use_multi_text = true;

packages/my_package/blocks/my_package/controller.php:
$captcha = Loader::helper('validation/captcha');
      if (!$captcha->check('code')) {
         $this->errors['code'] = $this->error_code;
      }

packages/my_package/blocks/my_package/view.php:
<?php 
         $captcha = Loader::helper('validation/captcha');
         $captcha->display(); 
         ?>
         <input type="text" id="code" name="code" value="<?php echo $code; ?>" maxlength="6" />

What am I missing?

Thank you very much.

linuxoid
 
linuxoid replied on at Permalink Reply
linuxoid
Anyone?
linuxoid replied on at Permalink Reply
linuxoid
Now I have found this:https://www.concrete5.org/documentation/developers/5.7/packages/addi... - but it still does not work. Here are my files:

packages/my_package/controller.php:
<?php        
    namespace Concrete\Package\MyPackage;
    use Package;
    use BlockType;
    defined('C5_EXECUTE') or die(_("Access Denied."));
    class Controller extends Package {
       protected $pkgHandle = 'my_package';
       protected $appVersionRequired = '5.7.1';
       protected $pkgVersion = '0.1';
       protected $pkgAutoloaderMapCoreExtensions = true;
       public function getPackageDescription() {
          return t('Contact Form');
       }
       public function getPackageName() {
          return t("Contact Form");

packages/my_package/src/Concrete/Captcha/MySecurimageController.php:
<?php
    namespace Concrete\Package\MyPackage\Captcha;
    use Securimage;
    use Securimage_Color;
    class SecurimageController extends \Concrete\Core\Captcha\SecurimageController
    {
        protected $securimage;
        public function __construct()
        {
       $this->securimage = new Securimage();
       $this->securimage->image_width = 237;
       $this->securimage->image_height = 60;
       $this->securimage->image_bg_color = new Securimage_Color('#F0F0F0');
       $this->securimage->line_color = new Securimage_Color('#333333');
       $this->securimage->use_multi_text = true;

What am I still missing?

Thank you.
linuxoid replied on at Permalink Reply
linuxoid
Could anyone please tell me how to customise the Captcha from my own package?

Thank you.
mesuva replied on at Permalink Reply
mesuva
Is this perhaps simply a case of it not being possible/supported with c5's architecture?

It makes sense to be able to override something like this globally, using the top level override folders, but if you were able to make changes like this from the package level you'd have all sorts of competing happening, conflicts, etc.

In other words, if you were able to do this, and then I did it in MY package, which one would actually come in effect?

Although I could certainly see the benefit from a package developers's point of view, from the view of someone installing such packages I don't think I'd be happy with a package changing core stuff - I could see that leading to breakages, etc. If I want to override core stuff, that's then up to me, but then also up to me to fix.
linuxoid replied on at Permalink Reply
linuxoid
"It makes sense to be able to override something like this globally, using the top level override folders, but if you were able to make changes like this from the package level you'd have all sorts of competing happening, conflicts, etc.

In other words, if you were able to do this, and then I did it in MY package, which one would actually come in effect? "

That's a valid reason. I haven't thought about it. Yes, what if I override the Captcha with my package, and then it's overridden by someone else's package? Which one takes priority?

Your right. Makes sense now. Thank you.