Alt Text in Image Block searchbable?

Permalink
Hello,

It seems, that the Alt-Text that I can enter with an Image Block is not searchable. Is there a way to change that behavior?

I have hundreds of images on my Website and only now I discovered that I can't search by these texts. I know that i could define a file attribute for this, but that would mean really lot of work to copy all these texts to the attribute. Also, if I use a file attribute, the same image would always have the same Alt-Text. But sometimes I use the image on different pages with with different Alt-Texts.

Thanks for your help!
Harald

HarryVienna
 
JohntheFish replied on at Permalink Best Answer Reply
JohntheFish
There is a method getSearchableContent() in a block controller that returns plain text of what is searchable within a block.

The best way to understand it is to look at an existing block such as the core content block (though many other blocks also implement getSearchableContent() ).

You have some choices:
1. Override the controller with a root level override and add your own version of getSearchableContent().
2. Create your own clone of the whole block under a new name, with your own version of getSearchableContent()
3. Create a new image block using something like Designer Content, though that will probably need some code tweaks once generated to do the above.
4. Make the change as a pull request on GitHub and hope it gets approved for subsequent version of c5.
HarryVienna replied on at Permalink Reply
HarryVienna
Thank you very much!

I wrote a simple controller.php with this content:

<?php 
   defined('C5_EXECUTE') or die("Access Denied.");   
   class ImageBlockController extends Concrete5_Controller_Block_Image {
      public function getSearchableContent(){
         return parent::getAltText();
      }
   }


After reindexing it works perfectly!

Cheers
Harald
kappi replied on at Permalink Reply
Hi, I've been looking to make images searchable in a photography site but haven't had any luck as yet.

Looked at the code above and wondered if you could tell me where I would implement this please.
benswmay replied on at Permalink Reply
Hi,

I finally got it. I placed it under the other public functions in the concrete/blocks/images/controller.php

It was calling an error for me so I used.

public function getSearchableContent(){
         return $this->altText;
      }


I reinstalled the block and rescanned the search index and it worked great.
benswmay replied on at Permalink Reply
Hi,

I am also having a similar problem. I attempted to place the code where I thought was needed but cannot get it to work. Either it does refresh the index and calls an error or it does nothing at all.

Could you let me know where you placed this code? It would help a bunch.

Sorry my skills are pretty light right now.
Thanks