Coder Social home page Coder Social logo

Comments (3)

esszett avatar esszett commented on June 14, 2024 1

Hello @wanze,

I didn't recognize the hookability… fantastico, that did it. Now I fetch the formatted output of the og_image field and processwire fetches the defined default values @field-settings.
This hooking scenario also provides a solution for another usecase I recently had: inherit values from the next available parent in page tree. That's useful in a deep nested tree where you have topic nodes of which values should be reflected on their childpages.

Thank you!

My simple hook in ready.php

$this->addHookAfter('SeoMaestro::renderSeoDataValue', function (HookEvent $event) {
    $group = $event->arguments(0);
    $name = $event->arguments(1);
    $value = $event->arguments(2);
    $page = $event->wire('page');
   
    if ($group === 'opengraph' && $name === 'image') {
        if ($value !== "") return;

            //scenario 1: fetch default image assigned in field-settings (get formatted)
            $value = $page->og_image;

            //scenario 2: inherit from next upper parent-page in tree with assigned image (no setting for default value @og_image)
            // $selector = "og_image!=''";
            // $value = $page->og_image ?: $page->closest($selector)->og_image;

            $event->return = $value;        
    }
});

from seomaestro.

wanze avatar wanze commented on June 14, 2024

Hi @esszett,

I moved your question to a new issue to keep things organized a bit.

That is very interesting, I actually didn't know about the feature to select a default value for the an image field. I think you are right, the fallback might only work when output formatting is on. I will look how to support this scenario. Or maybe you found it out already? :) In the meantime, you could rebuild this logic by hooking into the rendering process of the meta data. There are two hooks available, I am not sure which one is easier to use, see the test cases here: https://github.com/wanze/SeoMaestro/blob/master/tests/src/SeoMaestroTest.php#L83-L132
In your hook, you would need to return the url of the default image, if no image has been specified. Hope that helps!

Cheers

from seomaestro.

wanze avatar wanze commented on June 14, 2024

@esszett FYI, the fallback to the default page image is now respected by the module in version 0.7.0.

from seomaestro.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.