Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to set default settings in app config #4

Open
rimas-kudelis opened this issue Oct 19, 2015 · 6 comments
Open

Possibility to set default settings in app config #4

rimas-kudelis opened this issue Oct 19, 2015 · 6 comments
Assignees

Comments

@rimas-kudelis
Copy link

It would be nice if I could set default options for this widget somewhere in the application config file. Things like $defaultImage, $rating or $fileType aren't likely to vary between places within a single webapp.

@rlucian
Copy link

rlucian commented Oct 19, 2015

you probably know you can just use the widget as:

<?= \cebe\gravatar\Gravatar::widget([
    'email' => '[email protected]',
    'defaultImage' => 'blank',
    'options' => [
        'alt' => 'Carsten Brandt'
    ],
    'size' => 32
]) ?>

to add the blank image provided by gravatar... or replace value with 'monster' or your own url
i wouldn't expect you would need to place the gravatar widget in too many places in one app.

@rimas-kudelis
Copy link
Author

Even two places are enough to want a common place for config, aren't they? :)
E.g. I'm working on a blog now, and I want gravatars to be displayed near the post author name and near each comment. That's two places already, and I would like to configure things like defaultImage in a single place.

@cebe cebe self-assigned this Oct 19, 2015
@rlucian
Copy link

rlucian commented Oct 19, 2015

True.
I was also tempted to fork it for our use-case, but in the end didn't needed to.
But I guess you could just fork it and implement what you need, the code is actually quite simple.

@rimas-kudelis
Copy link
Author

Well I hope that maybe @cebe would be willing to implement this. If not, I'll consider forking, but more likely I'll just use the widget as it is now and specify that configuration separately for each instance.

@rimas-kudelis
Copy link
Author

OK, I found a way to achieve this: I added the following to the array returned by params.php:

'gravatar' => [
    'defaultImage' => 'retro',
    'rating' => 'g',
],

And then I can use these settings when placing the gravatar widget like this:

<?= Gravatar::widget([
    'email' => $model->email,
    'size' => 100,
    'defaultImage' => Yii::$app->params['gravatar']['defaultImage'],
    'rating' => Yii::$app->params['gravatar']['rating'],
    'options' => [
        'alt' => Yii::t('app', 'author'),
        'class' => 'img-responsive'
   ],
]) ?>

@cebe
Copy link
Owner

cebe commented Oct 20, 2015

related to yiisoft/yii2-bootstrap#89, you may check the DI solution linked there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants