Jump to content

Zeka

Members
  • Posts

    1,065
  • Joined

  • Last visited

  • Days Won

    11

Posts posted by Zeka

  1. setViewData([
    	'news' => $news->explode(function ($news_item) {
    		return WireData([
    			'title' => $news_item->title,
    			'date'  => $news_item->if('publish_from=today', 'yes', 'no'),
    			'link'  => $news_item->url
    		]);
    	})
    ]);

    This part looks very familiar to me))))

     

    Try something like 

    pages('id>1000')->each(function ($item) {
        $today = strtotime('today');
    	d(date("Y-m-d", $item->modified), $item->if("modified>=$today, modified<tomorrow", 'yes', 'no'));
    });

     

    • Like 1
  2. $wire->addHookBefore('InputfieldForm::render', function(HookEvent $event) {
    	$form = $event->object;
    	if($form->id !== 'ProcessPageEditLinkForm') return;
    	$inputfields = $form->children('name=link_page_id|link_page_file');
    
    	foreach ($inputfields as $inputfield) {
    			$inputfield->collapsed = Inputfield::collapsedHidden;
    	}
    
    	$tab = $form->child('id=link_attributes');
    	$tab->collapsed = Inputfield::collapsedHidden;
    });

     

    • Like 2
    • Thanks 1
  3. 58 minutes ago, szabesz said:

    Your proposal of adding toggle to the bar can take up lots of space too, if there are lots of languages in the system, so perhaps another way of solving the issue would be more feasible. Anyway, I get your point and the feature itself would be welcome, of course.

    Definitely would love to have such options. Language togglers could be hidden under same panel as 'change matrix type' panel. 

    • Like 1
  4. Guys, I need some clarifications here.
    I'm building catalog menu and depending on whether a page has children with 'category' template I change some part of my selector.

    Code that I use:

    <?php namespace ProcessWire;
    
    $layout->setTemplate('sidebar');
    
    $selector = [
    	'template'   => 'product',
    	'sort'       => 'title',
    	'categories' => page('id'),
    	'limit'      => 9
    ];
    
    if (page()->children->has('template=category')) {
    	$selector['categories'] = page()->children('template=category')->add(page());
    }
    
    $products = pages($selector);
    $sub_categories = page()->children('template=category');
    
    bd(page()->children()); // 7
    bd(page()->children('template=category')); // 8 

    As you can see in the first 'bd' I get 7 children and that is the right result. But it the second I get 8 children ( 7 children and current page which was added in if statement).

    I can't understand it from PHP side. For me, it's unintended behaviour as I'm calling function and waiting for a new result, but instead, I'm getting the result from an object from the previous call.

     

  5. 2 hours ago, lokomotivan said:

    In this case i loose ability to deactivate the page for some languages but for now i can live with it. 
    Creating a custom add new page is also an option, /module-manager/new/, and writing a custom form for adding new pages and handle it manually. But for page edit is not so easy

    You don't have to write custom module, you can use ProcessPageEdit as process for that page and omit executeEdit method in your process module.

  6. @lokomotivan 

    public function executeEdit() {
    
    	// breadcrumb
    	$this->fuel->breadcrumbs->add(new Breadcrumb($this->page->url, $this->page->title));
    
    	// Execute Page Edit
       $processEdit = $this->modules->get('ProcessPageEdit');
     	return $processEdit->execute();
    
    }

    Probably you will use something similar for adding new pages, but with ProcessPageAdd. So, by using this aproach for adding new pages you will get an issue with initial languages values. 

    chrome_3xXZAUkFAP.png

    As you can see all non-default languages are active.

    But, after page save they become disabled.

    chrome_CQ3dlp9hZl.png

    I was trying to resolve this issue but with no luck. So I went with creating addition page under the module page which reffers to custom module which extend ProcessPageAdd

    class ProcessCustomPageAdd extends ProcessPageAdd
    {
    
    	/**
    	 * @return array
    	 *
    	 */
    	public static function getModuleInfo() {
    		return array(
    			'title' => __('Page Add', __FILE__),
    			'summary' => __('Add a new page', __FILE__),
    			'version' => 108,
    			'permanent' => true,
    			'permission' => 'page-edit',
    			'icon' => 'plus-circle',
    //			'useNavJSON' => true,
    		);
    	}
    
    	public function init()
    	{
    		if ($this->wire('page')->parent->name == 'news-manager') {
    			$this->set('parent_id', 1036);
    		} else {
    				.....
    		}
    
    	}
    
    }

    Hope it helps.

    • Like 1
  7. @Leftfield  The path hook should be in ready.php and all logic should be in home.php or in the template file that you are using for root page. 

    if (input()->urlSegment(1) && input()->urlSegment(2) == 'pr' && input()->urlSegment(3)) {
    	$pagename = input()->urlSegment(1);
    	$hash = $input()->urlSegment(3);
    	$match = pages()->findOne("template=product, name={$pagename}, hash_field={$hash}");
    	if (!$match->id) throw new Wire404Exception();
    	echo $match->render();
    	return $this->halt();
    }

    Also you should enable URL segment for root ( home ) page.

    Generate hash and save it to hash field you can by hooking in Pages::saveReady. You can find a lot of exaples in the forum. 

    • Thanks 1
  8. @Leftfield I think that URL segmetns is the way to go.

    wire()->addHook("Page(template=product)::path", function($e) {
    		$page = $e->object;
    		$e->return = "/{$page->name}/pr/{$page->hash_field}/";
    	});

    Then you have to enable URL segments for your home template.

    And in template file 

    if (input()->urlSegment(1)) {
    	$pagename = input()->urlSegment(1);
    	$hash = $input()->urlSegment(3);
    	$match = pages()->findOne("template=product, name={$pagename}, hash_field={$hash}");
    	if (!$match->id) throw new Wire404Exception();
    	echo $match->render();
    	return $this->halt();
    }

     

    • Like 3
  9. Ok, then

    public function ___execute()
    {
    	$out = '';
    	$input = $this->wire('input');
    	$modules = $this->wire('modules');
    	$form = $this->modules->get("InputfieldForm");
    	$form->action = "./";
    	$form->method = "post";
    	$form->attr("id+name", "form_application");
    	$btn_application_create = $this->modules->get("InputfieldSubmit");
    	$btn_application_create->attr('id+name', 'hook_accept_application');
    	$btn_application_create->value = "Start Student";
    	$btn_application_create->addClass("ui-priority-primary button_submit");
    	$form->append($btn_application_create);
    
    	if ($input->post->hook_accept_application) {
    		$form->processInput($input->post);
    
    		if ($form->getErrors()) {
    			$out .= $form->render();
    		} else {
    			$this->addButtonsMethods();
    		}
    	} else {
    		$out = $form->render();
    	}
    
    	return $out;
    }
    
    public function addButtonsMethods($event)
    {
    	wire('session')->redirect(wire('pages')->get(123)->editUrl;
    }

     

    • Like 1
  10. Hi @Federico

    Why just not check for input post like 

    $modules = $this->wire('modules');
      $form = $this->modules->get("InputfieldForm");
      $form->action = "./";
      $form->method = "post";
      $form->attr("id+name", "form_application");
    if($this->wire('input')->post->your_submit_button) {
      $btn_application_create = $this->modules->get("InputfieldSubmit");
      $btn_application_create->attr('id+name', 'hook_accept_application');
      $btn_application_create->value = "Start Student";
      $btn_application_create->addClass("ui-priority-primary button_submit");
      $form->append($btn_application_create);
    }

     

  11. Hi.

    I'm trying to get embed data for some posts from Facebook using specified endpoint https://developers.facebook.com/docs/plugins/oembed-endpoints/. It works for all type of posts, but not for posts that match this pattern https://www.facebook.com/permalink.php?story_fbid={post-id}

    For example, this post 'https://www.facebook.com/permalink.php?story_fbid=1461042474038729&id=188990994577223' returns 404 when requesting URL 'https://www.facebook.com/plugins/post/oembed.json/?url=https://www.facebook.com/permalink.php?story_fbid=1461042474038729&id=188990994577223'

    Maybe it somehow relative to additional ID parameter in post URL, but I haven't seen URLs for post only with 'story_fbid'.

    So, I really can't figurate out what is the issue here. Maybe somebody faced such problem and can get some ideas of recommendations?

×
×
  • Create New...