Jump to content

Zeka

Members
  • Posts

    1,065
  • Joined

  • Last visited

  • Days Won

    11

Posts posted by Zeka

  1. I think that the first example would be more performant as every declaration of the hook creates an additional WireHook object that should be processed. While I think that difference in performance impact would be hard to measure in a typical PW site, I would stick with the first way not from the performance side, but from the side of structure, clarity, and repetition of the code, but it still depends on actual hook and what it is doing etc

    • Like 1
  2. Hi @Juergen

    Just tested and in my setup, if there are any nested fields in the fieldset with an error the parent fieldset is get automatically opened. From what I see in the code it is the intended behavior  https://github.com/processwire/processwire/blob/master/wire/core/InputfieldWrapper.php#L777

    In any case you can manually set collapsed state of inputfields inside the getModuleConfigInputfields

    public function getModuleConfigInputfields(array $data) {
    		
    		....
    
    		foreach ($inputfields->getErrorInputfields() as $inputfield) {
    			$inputfield->collapsed = Inputfield::collapsedNo;
    		}
    		
    		return $inputfields;
    	}

    or even like this 

    public function getModuleConfigInputfields(array $data) {
    		
    		....
    
    		foreach ($inputfields->getErrorInputfields() as $inputfield) {
    			$inputfield->collapsed = Inputfield::collapsedNo;
    			$parents = $inputfield->getParents();
    			
    			foreach ($parents as $parent) {
    				$parent->collapsed = Inputfield::collapsedNo;
    			}	
    		}
    		
    		return $inputfields;
    	}

     

    • Like 1
    • Thanks 1
  3. Hi @Matzn

    <?php namespace ProcessWire;
    
    class ParentModule extends WireData implements Module, ConfigurableModule
    {
    	public static function getModuleInfo() {
    		return [
    			'title' => 'Parent Module',
    			'version' => 1,
    		];
    	}
    
    	const defaultValue = '12345';
    
    	public function __construct() {
    		$this->set('api_user', self::defaultValue); // set default value in construct
    	}
    
    	public function getApiUser()
    	{
    		return $this->api_user;
    	}
    
    	public static function getModuleConfigInputfields(array $data) {
    		if(!isset($data['api_user'])) $data['api_user'] = self::defaultValue;
    
    		$form = new InputfieldWrapper();
    		$f = wire('modules')->get('InputfieldText');
    		$f->name = 'api_user';
    		$f->label = 'API USER';
    		$f->value = $data['api_user'];
    		$form->add($f);
    
    		return $form;
    	}
    }
    
    
    <?php namespace ProcessWire;
    
    class ChildModule extends ParentModule
    {
    
    	public static function getModuleInfo() {
    		return [
    			'title' => 'ChildModule',
    			'version' => 1
    		];
    	}
    
    	public function __construct() {
    		parent::__construct();
    		bd($this->getApiUser());
    		bd($this->wire()->modules->getModuleConfigData('ParentModule'));
    	}
    }

    Take a look at the construct method of ChildModule. 

    Without calling parent::__construct you will not be able to get what you want. 

    Also you can use $this->wire()->modules->getModuleConfigData('ParentModule') to get config data of module. 

    • Like 4
×
×
  • Create New...