Jump to content

Zeka

Members
  • Posts

    1,065
  • Joined

  • Last visited

  • Days Won

    11

Posts posted by Zeka

  1. @Macrura

    I have several hooks to before/after TemplateFile render method and typically I can exclude PW backend like

    $templateFile = $event->object;
    
            if ($templateFile->page->template == 'admin') {
                return;
            }

    or

    if ($this->wire('page')->template->name == 'admin') {
    	return;
    }

    But these checks fail for rendering settings pages and hooks are executed also for those template files in the admin panel and I get "PHP Notice: Trying to get property of non-object" as $this->wire('page') = null and there is no $event->object->page->template. 

    I'm not sure that it is directly relative to SettingsFactory, so I would ask you to check this behavior.

     

     

  2. Hi @WebMaster

    As far as I know, current only ImageExtra module adds support for additional fields for images. Native support for additional properties in image/files fields is on the roadmap for 2018. 

    For now, the most flexible route for you is to create a page for every image, in that way you will get all PW features. There is module that can help with this approach

     https://github.com/mr-fan/AutoImagePages

    14 minutes ago, WebMaster said:

    I cant use processwire features like images files sort.

    Do you mean that you can't sort and search by custom ImageExtra fields? 

    • Like 1
  3. What I would really like to see is more expanded multilanguage support in the core as 95% of my sites is ML. Very often I need to have some pages available only in non-default languages and every time I have to reinvent the wheel with custom logic.  Almost in all modern CMSs (Statamic, Craft, October ..)  you can separately publish or unpublish pages for every language even default. There are @adrian's module and request which intended to solve this issue via a module, but as I said, I think that it should be in core. 

    • Like 6
  4. Hi. 

    Not sure that it's important but here is my setup:

    // site/init.php
    
    wire()->addHookBefore('PageRender::renderPage', function (HookEvent $e) {
    	/** @var Page $page */
    	/** @var HookEvent $event */
    	/** @var Template $template */
    
    	$event = $e->arguments(0);
    	$options = $event->arguments(0);
    	$page = $event->object;
    	$template = $page->template;
    	$options['prependFiles'] = [
    		"{$template}.routes.php",
    		"_init.php",
    	];
    	$options['appendFiles'] = [
    		"layouts/_main.php",
    	];
    	$event->setArgument(0, $options);
    });

     

    // site/templates/_init.php
    
    $view = new \stdClass();
    $this->wire('v', $view, true);
    // site/templates/someteplate.php
    
    bd($v) ---> null
    
    bd(wire('v')); ---> stdClass

    So I'm confused why I can't directly access API variable through $v variable in this case but able through wire('v')?

    But if I move code from "site/templates/_init.php" to "site/init.php" it is accessible through $v in templates files. 

    Is it normal behavior? 

  5. Very often I have the same page name and title for all languages in ML context for some pages.

    So I create the page and only set title for default language (My title field is set to "Inherit from default language when blank, so it is ok to leave it blank).

    2.thumb.png.fef996b8ea07c0d419d2067050e2a4ce.png

    Then if you look at "Settings" tab you will see that name filed for non-default language is also filled with the value of default language. 

    3.thumb.png.3c2c6860aa2520d0c1574f9afd5d69b4.png

    UI tells that I have names for this page in both languages, but in the DB you will see the next:

    4.thumb.png.84136a5d5b1806b52dadfa417e8b3529.png

    Another way to get the same thing is to create a page with filled titles for both languages, save it, go to "Settings" tab and clear name field for non-default language and then save the page. UI will tell that you have page names for both languages, but in DB there will be the same picture as in the first example. Even if you manually enter the same name as in default language it will not get saved in DB.

    This behavior doesn't look intuitive for me and raises some issues.

    For example, this code will not work for these pages 

    	if(input()->urlSegment2)
    		throw new Wire404Exception();
    
    	if(input()->urlSegment1) {
    		$pagename = input()->urlSegment(1);
    		$language = user('language');
    		$nameFieldSelector = $language->isDefault() ? "name" : "name" . $language;
    		bd($nameFieldSelector);
    		$match = pages()->findOne("template=blog-category|blog-item, $nameFieldSelector={$pagename}");
    		bd($match);
    		if(!$match->id)
    			throw new Wire404Exception();
    
    		echo $match->render();
    		return $this->halt();
    	}

    And this also will return a blank line.

    $language = $user->language;
    $pageName = $page->localName($language); // ""

    Of course there are workarounds for these particular cases but the current behavior of ML name field makes it not clear in some situation do I have a name for language or I don't. 

    What do you think about it? How it possible to improve UI part? 

    Should I raise issue for it?

  6. Hi @dragan

    First of all thank you for your help @adrian @dragan

    I was wrong about localPath and localName. They are hookable. The problem was that I never called them in my templates, so didn't get any changes.

    $pages->addHookAfter("Page(template=projects-category|project)::localUrl", function (HookEvent $e) {;
        $page = $e->object;
        $pages = wire('pages');
        $user = wire('user');
        $language = $user->language;
        $langSegment = $pages->get("/")->localPath($language);
        $pageName = $page->localName($language);
        if ($page->matches("has_parent=projects")) {
            $e->return = $langSegment . "projects/$pageName/";
        } elseif ($page->matches("has_parent=products")) {
            $e->return = $langSegment . "products/$pageName/";
        }
    });

    Hook to Page::path also works. The issue was in my "matches" selector )))))

    $pages->addHookAfter("Page(template=projects-category|project)::path", function (HookEvent $e) {
        $page = $e->object;
        $pages = wire('pages');
        $user = wire('user');
        $language = $user->language;
        $langSegment = $pages->get("/")->localPath($language);
        $pageName = $page->localName($language);
        if ($page->matches("has_parent=projects")) {
            $e->return = $langSegment . "projects/$pageName/";
        } elseif ($page->matches("has_parent=products")) {
            $e->return = $langSegment . "products/$pageName/";
        };
    }, array('priority'=>101));

     

    • Like 1
  7. Hi.

    I'm working on ML site and trying to hooks page url/path.

    Here the code that I'm using:

    $pages->addHookAfter("Page(template=projects-category|project)::path", function (HookEvent $e) {
        $page = $e->object;
        if ($page->matches("has_parent=/projects/")) {
            $e->return = "/projects/$page->name/";
        } elseif ($page->matches("has_parent=/products/")) {
            $e->return = "/products/$page->name/";
        }
    });

    Nothing fancy and it works when default language is active. But when I switch to non-default langauge I get default page url.

    As far as I see the issue is relative to other Page::path hook in LanguageSupportPageNames.module.

    I was trying to prioritize hook by passing

    array('priority'=>2000)

    as last argument, but it doesn't sole the issue.

    Any  thoughts?

×
×
  • Create New...