• Content count

  • Joined

  • Last visited

Community Reputation

87 Excellent

About valan

  • Rank
    Distinguished Member
  • Birthday 12/13/1973

Profile Information

  • Gender
  • Location
    Russia, Moscow

Recent Profile Visitors

5,836 profile views
  1. @arjen thanks! Checked with different selector types = exactly what I need! Just minor fix - adding $selector2 needs to be done through new Selectors($selector2).
  2. @AndZyk thanks. Yes, there are associative and regular arrays used for selectors. It is exactly a reason of the question - how to merge them and get one: $selector1 = 'template=basic-page|product'; $selector2 = [ 'title|body%=' => $sanitizer->text($input->get('q')), ]; $selector3 = [ ['categories', '=', $input->get('categories'), 'int'], ['sort', '-created'] ] $selector = mergeSelectors($selector1, $selector2, $selector3); // <- I need this kind of method $results = $pages->find($selector);
  3. How to merge selectors of different types (string, array, array of arrays, Selectors) and get $selector with some of these types (to pass it to $pages->find($selector))?
  4. At our site we use both email and phone authorizations at frontend. To make life easier, I've developed HelperPhone pack that handles phone numbers. This pack includes following modules for ProcessWire CMS/CMF: FieldtypePhoneNumber: module that stores phone numbers InputfieldPhoneNumber: module that renders inputfield for phone numbers HelperPhone: module that loads PhoneNumber and PhoneNumberConst classes, and 'libphonenumber' namespace All these modules require included PW WireData-derived class PhoneNumber and PhoneNumberConst. PhoneNumber class is a thin wrapper over giggsey/libphonenumber-for-php, itself is port of Google's libphonenumber. PhoneNumberConst class stores constants, used by PhoneNumber class Usage: PhoneNumber class $phone = '8 (916) 318-07-29 ext 1234'; // input string could be in any phone-recognizable format $phoneNumber = new PhoneNumber($phone, 'RU'); // or wire('modules')->get('HelperPhone')->makePhoneNumber($phone, 'RU'); echo ($phoneNumber->isValidNumber() ? 'Yes':'No'); // Yes echo ($phoneNumber->isValidNumberForRegion($regionCode) ? 'Yes':'No'); // Yes echo $phoneNumber->getNumberTypeTitle(); // Mobile echo $phoneNumber->getCountryCode(); // 7 echo $phoneNumber->getRegionCode(); // RU echo $phoneNumber->getNationalNumber(); // 9163180729 echo $phoneNumber->getExtension(); // 1234 echo $phoneNumber->formatForCallingFrom('US') // 011 7 916 318-07-28 echo $phoneNumber->formatForCallingFrom('GE') // 00 7 916 318-07-28 For more methods and properties please refer to PhoneNumber and PhoneNumberConst source files. Need more? Check giggsey/libphonenumber-for-php and use it by accessing $phoneNumber->phoneNumber property - it is instance of \libphonenumber\PhoneNumber or null (if empty). Usage: field Note: on field creation, make sure that you've configured field settings Default region: assumed region if input phone number string is not in international format (starts with '+', etc) Enabled/disabled phone extentions: if disabled, phone extension will be removed on field save. Phone field settings in example below: default region code 'RU', phone extensions are enabled echo $page->phone; // +79163180729 // Note1: $page->phone stores instance of PhoneNumber and renders to string in E164 format. // Note2: E164 format does not include extension. echo $page->getFormatted('phone'); // +7 916 318-07-29 ext. 1234 echo $page->getUnformatted('phone'); // +79163180729 echo $page->phone->format(PhoneNumberConst::RFC3966); // tel:+7-916-318-07-29;ext=1234 echo $page->phone->getNationalNumber(); // 9163180729 Usage: PW selectors FieldtypePhoneNumber is instance of FieldtypeText. It stores phone numbers and extensions as string in E164 format with #extention (if provided by user and enabled in settings) E.g. in db it looks like this: '+79163180729#1234'. This makes it easy to query fields as any text field. echo $pages->find([ 'template' => 'my_temlate', 'phone^=' => '+79163180729', ]); // will echo page ids where phone starts with '+79163180729' Finally I've decided to put it here first and later to Modules directory (based on your feedbacks). GitHub: Enjoy
  5. @LostKobrakai - thank you! link is very helpful. P.S. and thank you for article - helped me a lot to better structure and maintain the code.
  6. There is excellent article here by @LostKobrakai that describes how to use custom page types and extend the Page class. Q: How to extend (e.g. w/o hooks, using method described in article) core Users and User classes and reload $users and $user api variables (they are locked) with new/extended classes? Currently I think about changing User to MyUser class in systems tab (e.g. set another class to be used for 'user' template) and installing module like below. As you can see it adds $myusers and $myuser api variables but I'm not sure that it won't conflict with core. // MyUsers.php class MyUsers extends Users { public function __construct(ProcessWire $wire, $templates = array(), $parents = array()) { parent::__construct($wire, $templates, $parents); $this->setPageClass('MyUser'); } // my non-overlapping methods here ... } // MyUser.php class MyUser extends User { // my non-overlapping methods here ... } class ResourceUser extends WireData implements Module { public static function getModuleInfo() { return [ 'title' => 'Extend Users and User', 'version' => 100, 'autoload' => true, 'singular' => true, ]; } public function __construct() { require_once(dirname(__FILE__) . '/MyUsers.php'); require_once(dirname(__FILE__) . '/MyUser.php'); } public function init() { $pagesType = new MyUsers($this->wire); $this->wire('myusers', $pagesType, true); $page = new MyUser; $this->wire('myuser', $page, true); } }
  7. @ryan may be you can help? Thanks.
  8. @Robin S @LostKobrakai thanks. This method looks like a right method for input-specific js/css. It creates config under $this->attr('id') on initial page load... but now w/o values. Looks like when Ajax visibility is set, PW knows $this->attr('id') but doesn't know $this->my_config_key and $this->attr('value'). How to get these values in this method when Ajax visibility is set? P.S. If visibility set to "Open", everything works OK, e.g. it does not work with 2 Ajax visibility options. public function renderReady(Inputfield $parent = null, $renderValueMode = false) { $this->config->js($this->attr('id'), [ 'config' => [ 'my_config_key' => $this->my_config_key, // = null (it's an inputfield config parameter) 'pageId' => $this->attr('value'), // = 0 (it's a page id from InputfieldPage) ], ]); parent::renderReady($parent, $renderValueMode); }
  9. @Robin S thanks for check. Looks like problem is deeper. May be at MySQL level as we've migrated to InnoDb. Or smth else. And thanks for sensible advice!
  10. @arjen thanks. I guess that such kind of errors like "endless loops somewhere in the core" require line-by-line execution debugger in order to find where it occurs. Not sure that Tracy may help here, but will give it a try. I also think its a core issue, not site-specific. Could you check it in admin? - move any page under any user (preliminary make sure you've enabled 'may have children' in user template). Page will be moved, but spinner will continue to run, blocking any further work in admin, so you'll need to create a new session (restart browser/login again).
  11. @kixe thanks. $page already exists, so no need to set template again. Anyway, I did it but issue remained - the same $page->save(). I'm not really advanced enough programmer to debug PW core code (and don't have proper debugging tools, wire('log')->error('My error'); was always enough for me))
  12. Code below works everywhere else, except if applied to pages in Admin tree. Specifically, I change parent to some 'user-car' pages and place them under some 'user' page in admin tree. $page->of(false); $page->parent = $some_user_page; $page->save(); $page->save() freezes, e.g. method does not not return any value/looks like in falls in endless loop somewhere inside. It also does not generate any errors. As it happens only in Admin tree (everywhere else it works), root cause could be: (1) in template settings (I've checked and didn't found any "restrictions", e.g. 'user-car' pages can be freely moved, 'user' may have children) or (2) in core code, somewhere in Page::save() Please, advise how to fix this issue.
  13. Well, specifically, I'm interested to know how to pass js to the page on ajax call. Currently ajax-driven inputfields work only for fields that do not set js inside render(). But what to do if I have such code in render()? $this->wire('config')->js($this->attr('id'), [ 'config' => $my_array, ]); Moving it to init() does not work, as $this->attr('id') is not set at that moment. Adding js script (with <script>my_js_code_that_sets_config();</script>) to redner() output also does not work - script tags are removed by PW. P.S. Just in case if it matters - I'm developing inputfield for FieldtypePage, e.g. it is added to InputfieldPage inputfieldClasses setting.
  14. @Zeka hi! This file has only declaration of constants. There should be better sources to learn
  15. I'd like to create custom ajax-driven inputfield. Ajax-driven inpufields where introduced here:, but since that time I haven't seen any "how-to" tutorials. I'd like to learn from core code, but can't understand which files to check. Can someone suggest which core/module files I have to check in order to learn from code and be able to create custom ajax-driven inputfields?