Media Images Alt and Title in media Manager

Hello,
It is important for SEO to have alt text and title text. however i am not finding any option to enable/disable it in media manger and there is no place to put those details.

what can i do in this case?

thank you in advance.

If you have control over the structure of your data, you can add a text field in the backend side for the text.

However, you could use the file upload widget. Every image that is uploaded using that widget has its own title and description that you can use.

Thank you @artistro08.

I am talking about Media Manager itself.

If you check the image i want to add some fields to the box in red.

Ahh okay.

That isn’t supported and hasn’t been supported for a long time.

If my memory serves me well, I know the founders are creating something to address that. I could be wrong tho

Ah that’s a shame. this is really need for SEO @Amin #request_for_feature

1 Like

I think there is also not really a need for that. You can set those attributes when you place the image.
If you’re using the CMS Editor, you have control over the markup anyway. If you’re using the richeditor widget (with the static pages plugin or as a field for you model) you can set the alt tag with the button in the image context menu. And in other cases like repeater fields, models or Tailor blueprints you also have full control over what you want to be editable.

On the other hand, if you could set those attributes in the Media Manger, the Media Manager would need to be rewritten to be database dependent (or any storage method that can save those attributes) and the alt attributes will be wrong, or at least not perfectly suitable, when there are placed anyway.

One thing that would be nice though, would be a “Describe & insert” button, like the “Crop & insert” button. This would make the placement and description a single step. But thats just a small inconvenience imho.

Simple: if you need alts/titles - use attachments (fileupload widget).

@marco.grueter you are absoulutely right.

USE CASE:
we are using configurations to upload an image. The relation would therefore be needed for this image. but the settingFields is unable to have any relationship in this case.

e.g
i am using this special model from OctoberCms

(https://docs.octobercms.com/2.x/plugin/settings.html)

Now there is an image field also in the Config. this only works when you have media image from Manager. But if i put file upload widget there should be a relationship to that particular key like the attachOne.

So may be i am wrong but having this problem.
i would like to put the field as file upload but then the problem is with the relation.
How you solve this? How can you put a config key as a relationship?

Thank you in advance

Yes, I saw your other post, but wasn’t sure what the problem could be.
But now I saw the word “Controller” in the error. Make sure your calling the right class. Looks like your trying to call your controller (called MySettingsController ?) when you wanted to use the model.

And, to be more in line with this discussion, you can always add more fields to your settings model to let the user configure the alt and description attribute or whatever you need. This way you could also use the media finder if this suits your need better and get the alt tags from a different field.

Thank you. Yes the controller Namespace is a typo here.

So you means extra two fields (title and caption) for the Media Upload Image right?
That would do the trick for sure.

More of a learning question:
would it be not nice to relates the config model key to an attachement?
e.g: let’s say i have an image key called f_image now i want to have the attachement for this image. is there any way i can relate this config key to an attachement?

like so

let’s say the

public $settingsCode = ‘my_setting_code’;

and the field name is f_image

public $attachOne = [
‘my_setting_code[f_image]’ => ‘System\Models\File’
];

is there anyway to achieve this?

Thanks alot for your time <3

Ah yes, you can do that. You probably overlooked that the $settingsFields member of the settings model takes a form fields definition, just like your other models.

example:

File: [namespace]/[plugin]/models/Settings.php

class Settings extends Model
{

    public $attachOne = ['yourfile' => \System\Models\File::class];

    /**
     * @var string settingsCode unique to this model
     */
    public string $settingsCode = 'my_plugin_settings';

    /**
     * @var string settingsFields configuration
     */
    public string $settingsFields = 'my_settings_fields.yaml';

[ ... ]

File: [namespace]/[plugin]/models/settings/my_settings_fields.yaml

fields:
    yourfile:
        label: An image or something
        type: fileupload
        mode: image

[ ... ]

Seem to be working fine, I’ve just tested it on a OCM V2 latest installation (sorry, don’t have a V3 handy at the moment).

One thing though: I think you will have the access through the instance, it might not be possible with the get helper method. E.g.: YourSettingsModel::instance()->yourfile->path instead of YourSettingsModel::get('yourfile')

Hope that helps!

@marco.grueter Thank you so much.
i guess i am very near to it.

This works: YourSettingsModel::instance()->yourfile->path

The relation is empty so there is this error now.

Attempt to read property "path" on null

Any thought on that how can i assign a dummy relationship before the fields?

I already tried

(https://octobercms.com/forum/post/call-to-a-member-function-hasrelation-on-null-error-message?page=1)

Thank you for your time. I really appreciate it.

I’m glad to help you out, no problem. But I am unsure where you are stuck now.

If you’re asking if you can set default values for your settings model - you are in luck!

    /**
     * Default values to set for this model, override
     */
    public function initSettingsData()
    {
         $this->yourfile = '/absolute/path/to/yourfile.jpg;
    }

You can override this function in your settings model, to initialize your settings with default data.
Set them as a member variable or explicit with the helper functions.

Also check out the hints for creating file attachments at File Attachments - October CMS - 2.x

Cheers!

@marco.grueter thanks alot for helping me out.

I followed your tutorial. and used
YourSettingsModel::instance()->yourfile->path

in the formExtendFields Method to populate the form. now the hasRelation error is gone but getting a new error

Attempt to read property "path" on null

I am setting it like this

$form->getField('yourfile')->value = FellowzSettings::instance()->yourfile->path;

Forgive my ignorance but stuck in a small thing.

i tried in the Model

$file = new File();
        $file->fromUrl('http://my.local/storage/app/media/logo_light.png');
        $this->f_image->add($file);

but the error still persists.

@marco.grueter I finds the problem.

i am using a custom controller (i dont know why :P) but when i use the settings page. then all of a sudden i dont need a custom controller and all workd well.

Thanks alot for helping me out <3.

btw the controller method made me curious now :stuck_out_tongue:

2 Likes