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

[Feature request] - Ability to disable/alter meta tags generated by core / core plugins. #1946

Closed
lonalore opened this Issue Oct 19, 2016 · 11 comments

Comments

3 participants
@lonalore
Member

lonalore commented Oct 19, 2016

I have been working on my Metatag project for a while, and I would like to generate all kind of meta tags with my plugin as soon as I finish it. But for achieving this, I need an option to disable all meta tags generated by core. How can I achive this? Thanks!

@lonalore

This comment has been minimized.

Show comment
Hide comment
@lonalore

lonalore Oct 19, 2016

Member

Another suggestion: provide a way to alter meta tag array before rendering.

Member

lonalore commented Oct 19, 2016

Another suggestion: provide a way to alter meta tag array before rendering.

@lonalore lonalore changed the title from [Feature request] - Ability to disable meta tags generated by core / core plugins. to [Feature request] - Ability to disable/alter meta tags generated by core / core plugins. Oct 19, 2016

@lonalore

This comment has been minimized.

Show comment
Hide comment
@lonalore

lonalore Oct 20, 2016

Member

@CaMer0n can you review my commit? I think it's a pretty good solution for altering meta tags before rendering. And e107::getAddonConfigAlter() can be also used for altering arrays are provided by config() (and other) methods.

Member

lonalore commented Oct 20, 2016

@CaMer0n can you review my commit? I think it's a pretty good solution for altering meta tags before rendering. And e107::getAddonConfigAlter() can be also used for altering arrays are provided by config() (and other) methods.

@Moc Moc added the enhancement label Oct 21, 2016

@CaMer0n

This comment has been minimized.

Show comment
Hide comment
@CaMer0n

CaMer0n Oct 23, 2016

Member

@lonalore It's good, but I'm not a fan of meta_alter().. I believe it would be more consistent with other core methods to find a way to use an $override parameter with e107::meta()

Member

CaMer0n commented Oct 23, 2016

@lonalore It's good, but I'm not a fan of meta_alter().. I believe it would be more consistent with other core methods to find a way to use an $override parameter with e107::meta()

@lonalore

This comment has been minimized.

Show comment
Hide comment
@lonalore

lonalore Oct 24, 2016

Member

Hmm. But I don't want to override e107::meta() because it works fine. I just want to alter the meta tag array before rendering. Anyway I'll look into how this $override paramter really works.

Member

lonalore commented Oct 24, 2016

Hmm. But I don't want to override e107::meta() because it works fine. I just want to alter the meta tag array before rendering. Anyway I'll look into how this $override paramter really works.

@lonalore

This comment has been minimized.

Show comment
Hide comment
@lonalore

lonalore Oct 24, 2016

Member

Well, I have no idea how we could use $override for altering $_meta before rendering. :(

Member

lonalore commented Oct 24, 2016

Well, I have no idea how we could use $override for altering $_meta before rendering. :(

@CaMer0n

This comment has been minimized.

Show comment
Hide comment
@CaMer0n

CaMer0n Oct 24, 2016

Member

@lonalore I understand better what you want. I have added a few methods to help.

Member

CaMer0n commented Oct 24, 2016

@lonalore I understand better what you want. I have added a few methods to help.

@CaMer0n

This comment has been minimized.

Show comment
Hide comment
@CaMer0n

CaMer0n Oct 24, 2016

Member

Example e_header.php content:

    $front = eFront::instance();
    $response = $front->getResponse();
    $data = $response->getMeta();

    foreach($data as $m)
    {
        if($m['name'] == 'viewport')
        {
            $response->setMeta('viewport', 'replaced');
        }

    }
Member

CaMer0n commented Oct 24, 2016

Example e_header.php content:

    $front = eFront::instance();
    $response = $front->getResponse();
    $data = $response->getMeta();

    foreach($data as $m)
    {
        if($m['name'] == 'viewport')
        {
            $response->setMeta('viewport', 'replaced');
        }

    }
@lonalore

This comment has been minimized.

Show comment
Hide comment
@lonalore

lonalore Oct 25, 2016

Member

Thank you @CaMer0n ! But with this I would be able to alter meta tags already added by core/plugins. But I cannot alter e.g the meta tags of social plugin, because its e_header.php is called after my e_header.php. I hope you understand it! :D

So, I need a solution I can use right before rendering: here

For example an event triggering?

    /**
     * Render meta tags, registered via addMeta() method
     * @return string
     */
    public function renderMeta()
    {
        $attrData = '';

        $event = e107::getEvent();
        $event->trigger('render_meta_pre');

        foreach ($this->_meta as $attr) 
        {
            $attrData .= '<meta';
            foreach ($attr as $p => $v) 
            {
                $attrData .= ' '.preg_replace('/[^\w\-]/', '', $p).'="'.str_replace(array('"', '<'), '', $v).'"';
            }
            $attrData .= ' />'."\n";
        }
        return $attrData;
    }

Then I could use your code in my registered event callback (in my e_module.php):

$event = e107::getEvent();
$event->register('render_meta_pre', 'my_callback');

function my_callback()
{
    $front = eFront::instance();
    $response = $front->getResponse();
    $data = $response->getMeta();

    foreach($data as $m)
    {
        if($m['name'] == 'viewport')
        {
            $response->setMeta('viewport', 'replaced');
        }

    }
}

What do you think about this?

Member

lonalore commented Oct 25, 2016

Thank you @CaMer0n ! But with this I would be able to alter meta tags already added by core/plugins. But I cannot alter e.g the meta tags of social plugin, because its e_header.php is called after my e_header.php. I hope you understand it! :D

So, I need a solution I can use right before rendering: here

For example an event triggering?

    /**
     * Render meta tags, registered via addMeta() method
     * @return string
     */
    public function renderMeta()
    {
        $attrData = '';

        $event = e107::getEvent();
        $event->trigger('render_meta_pre');

        foreach ($this->_meta as $attr) 
        {
            $attrData .= '<meta';
            foreach ($attr as $p => $v) 
            {
                $attrData .= ' '.preg_replace('/[^\w\-]/', '', $p).'="'.str_replace(array('"', '<'), '', $v).'"';
            }
            $attrData .= ' />'."\n";
        }
        return $attrData;
    }

Then I could use your code in my registered event callback (in my e_module.php):

$event = e107::getEvent();
$event->register('render_meta_pre', 'my_callback');

function my_callback()
{
    $front = eFront::instance();
    $response = $front->getResponse();
    $data = $response->getMeta();

    foreach($data as $m)
    {
        if($m['name'] == 'viewport')
        {
            $response->setMeta('viewport', 'replaced');
        }

    }
}

What do you think about this?

@CaMer0n

This comment has been minimized.

Show comment
Hide comment
@CaMer0n

CaMer0n Oct 27, 2016

Member

@lonalore It did cross my mind after I committed the code about the 'order of things' issue.
I like your solution. Commit coming shortly.

Member

CaMer0n commented Oct 27, 2016

@lonalore It did cross my mind after I committed the code about the 'order of things' issue.
I like your solution. Commit coming shortly.

@CaMer0n CaMer0n closed this in fe56126 Oct 27, 2016

@CaMer0n CaMer0n added this to the e107 v2.1.2 milestone Oct 27, 2016

@lonalore

This comment has been minimized.

Show comment
Hide comment
@lonalore

lonalore Oct 27, 2016

Member

Thank you very much! It works like a charm! :)

Member

lonalore commented Oct 27, 2016

Thank you very much! It works like a charm! :)

@Moc

This comment has been minimized.

Show comment
Hide comment
@Moc

Moc Oct 27, 2016

Member

Re-opening for documentation reminder

Member

Moc commented Oct 27, 2016

Re-opening for documentation reminder

@Moc Moc reopened this Oct 27, 2016

@Moc Moc removed this from the e107 v2.1.2 milestone Oct 27, 2016

@Moc Moc self-assigned this Oct 27, 2016

@Moc Moc added documentation and removed enhancement labels Oct 27, 2016

@Moc Moc unassigned CaMer0n Oct 27, 2016

@Moc Moc closed this Jun 23, 2018

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