Jump to content

dadish

Members
  • Posts

    112
  • Joined

  • Last visited

  • Days Won

    8

Everything posted by dadish

  1. Of course. In one of your templates (edit: In one of your template files) you simply do <?php echo $modules->get('ProcessGraphQL')->executeGraphQL(); and that's it. It will handle all GraphQL requests. There is more info in the repository.
  2. Yes, I am aware of field permissions, thank you for reminding. I have not added support for them yet. Though it is definitely in my todo list for this module.
  3. By the way, in terms of security, this module follows the permission settings in ProcessWire. All it does is collects the templates that are viewable by the client via $user->hasPermission('page-view', $template); and for every request it makes sure to returns only those pages that have one of those templates. So, as long as user does not have permission to view the page, she won't be able to fetch it. I tried to make module reflect your existing settings as much as possible. It basically delegates everything possible to ProcessWire itself. That is so true. I personally thought GraphQL was new SQL.
  4. NOTE: This thread originally started in the Pub section of the forum. Since we moved it into the Plugin/Modules section I edited this post to meet the guidelines but also left the original content so that the replies can make sense. ProcessGraphQL ProcessGraphQL seamlessly integrates to your ProcessWire web app and allows you to serve the GraphQL api of your existing content. You don't need to apply changes to your content or it's structure. Just choose what you want to serve via GraphQL and your API is ready. Warning: The module supports PHP version >= 5.5 and ProcessWire version >= 3. Links: Zip Download Github Repo ScreenCast PW modules Page Please refer to the Readme to learn more about how to use the module. Original post starts here... Hi Everyone! I became very interested in this GraphQL thing lately and decided to learn a bit about it. And what is the better way of learning a new thing than making a ProcessWire module out of it! For those who are wondering what GraphQL is, in short, it is an alternative to REST. I couldn't find the thread but I remember that Ryan was not very happy with the REST and did not see much value in it. He offered his own AJAX API instead, but it doesn't seem to be supported much by him, and was never published to official modules directory. While ProcessWire's API is already amazing and allows you to quickly serve your content in any format with less than ten lines of code, I think it might be convenient to install a module and have JSON access to all of your content instantly. Especially this could be useful for developers that use ProcessWire as a framework instead of CMS. GraphQL is much more flexible than REST. In fact you can build queries in GraphQL with the same patterns you do with ProcessWire API. Ok, Ok. Enough talk. Here is what the module does after just installing it into skyscrapers profile. It supports filtering via ProcessWire selectors and complex fields like FieldtypeImage or FieldtypePage. See more demo here The module is ready to be used, but there are lots of things could be added to it. Like supporting any type of fields via third party modules, authentication, permissions on field level, optimization and so on. I would love to continue to develop it further if I would only know that there is an interest in it. It would be great to hear some feedback from you. I did not open a thread in modules section of the forum because I wanted to be sure there is interest in it first. You can install and learn about it more from it's repository. It should work with PHP >=5.5 and ProcessWire 3.x.x. The support for 2.x.x version is not planned yet. Please open an issue if you find bugs or you want some features added in issue tracker. Or you can share your experience with the module here in this thread.
  5. Made a little patch (0.1.1). Now it checks if the field is editable and if the page is locked before showing you the button. I was about to submit the module into Modules directory, but then I encountered the ProcessWire version compatibility field. The highest option is 2.6 and this module supports only 2.6.5 and higher. Can anybody confirm that I wont be able to publish it until 2.7 ?
  6. Ooops, didn't see the @diogo's post while editing mine. Sorry.
  7. Hello and welcome! I am not good at MySQL really. But you could achieve that with php script. The below code is an example, not tested yet. But you should get the idea. <?php // First get all the pages you want to manipulate $list = $pages->find("template=example"); // The language from which you want the values $langFrom = $languages->get('fr-fr'); // The language into which you want the values $langTo = $languages->get('fr-be'); // List of all fields that should be copied // if a page has it. Some fields does not have a // multiple language entries. Like Images, Files, Checkboxes // this will help us avoid errors $validFields = array( 'title', 'body', 'summary', 'sidebar' ); // Loop through pages foreach ($list as $p) { // Turn off outputFormatting $p->of(false); // then loop through each field foreach ($p->fields as $field) { // If the field is not one of those we want to copy then ignore if (!in_array($field->name, $validFields)) continue; // Get the value of the field for from language $fromValue = $p->getLanguageValue($langFrom, $field->name); // Here you can do any manipulations to your value // if you want to alter it a little // ... // ... // Set the value of the field for to language $p->setLanguageValue($langTo, $fromValue); } $p->save(); echo "$p->title is updated<br />"; } Note: If there are too many pages on which you need to perform this, consider limiting the list and doing it with small batches. Like... <?php $limit = 100; $page = 1; $start = ($page - 1) * $limit; $list = $pages->find("template=example, limit=$limit, start=$start"); // and the rest is like above // ...
  8. Quickly toggle your checkboxes with extra action buttons via AJAX. The module adds functionality to InputfieldCheckbox so you can toggle the checkbox fields in the extra action buttons intruduced in ProcessWire 2.6.5 via AJAX. Github Page Download Link Requirements This module works only for ProcessWire versions later than 2.6.5. How to Install 1. Copy the files to /site/modules/ProcessQuickToggle/ 2. In your admin, go to Modules > Refresh for new modules. 3. Click the "Install" button next to "Process Quick Toggle". Usage Go to any checkbox field you want to enable quick toggle feature for. Setup > Fields > my_checkbox_field. There in the Input tab you should see an Enable Quick Toggle field. After you check it you will see some fields that you can fill based on your needs. Then save the field. Now there should be an extra button for every page that has this field in the Pages tree. Features Supports template contexts. Supports core FontAwesome icons. Any kind of feedback is appreciated.
  9. That's not entirely correct. If you don't check the "active" checkbox under Settings when editing a page, the page is not listed for users with this language, e.g. excluded from $pages->find calls. I'm not sure what the default behaviour is when you visit the page directly in a language which is not active. Maybe you'll see the content in the default language. In this case, I'm sure you could also hook into somehwere and throw a 404 or do the prefered action. Yep. You're right. I did not even know that. I guess the difference with this module is only the contextual approach to the multi-language sites. I don't think this module is any better than the core LanguageSupport module, just the other way of doing things. I posted it here for community to decide. If we decide we don't need it the thread will stay only for historical reasons I guess. Another thing might be the hassle with FieldTypes that do not support multi-language. FieldtypeFile and FieldtypeImage for instance. I know that you can have multi-language descriptions. But what about files themselves. You can't have different files for different languages.
  10. ProcessWire does not support tree based multi-language sites. This is just another approach to handle sites with many languages. Some people prefer to do it this way. There are cases where websites have 600 pages in english, 700 pages in russian and only 300 pages in english and russian. In this case it is much better to keep the content separate, each under one section and have their translations linked. In case for core LanguageSupport module. When you publish an article in english, it will be shown in the russian version of the site too, even if there isn't a russian version of the article. It will also will show in places like navigation, on sidebar with the latest news etc. However if you put everything english under one page and build every parts of your site under that page (your navigation root, latest news) then your article in english language will never be seen in russian version. Update: The last paragraph is not entirely correct. See the comment by @Wanze below.
  11. Babel is a module that provides functionality for managing section based multilanguage sites. It is inspired by Babel Plugin for MODX. There are cases where websites have 600 pages in english, 700 pages in russian and only 300 pages in english and russian. In this case it is much better to keep the content separate, each under one section and have their translations linked. This module helps you to manage those links. Github Page Download Link How to Install Warning Backup your database before installing this module. Requirements Babel works on top of core LanguageSupport module. You will have to install it first and create languages for your site. Then: 1. Copy all the module files to /site/modules/Babel/ 2. In your admin, go to Modules > Refresh for new modules. 3. Click the "Install" button next to Babel. Settings First of all you should set the root page for each language. Usually section based multilingual sites will have a structure like... Root |__Home (English) |__About |__News |__ News Article 1 |__ News Article 2 |__ News Article 3 |__ News Article 4 |__Contact ... |__Главная (Russian) |__О нас |__Новости |__ Новостная статья 1 |__ Новостная статья 2 |__ Новостная статья 3 |__ Новостная статья 4 |__Связаться ... |__Baş Sahypa (Turkmen) |__Barada |__Habarlar |__ Habar Makalasy 1 |__ Habar Makalasy 2 |__ Habar Makalasy 3 |__ Habar Makalasy 4 |__Aragatnaşyk ... You just need to select the languages that you want Babel to manage and select the root pages for each of them. API Babel creates couple useful methods and a properties for you. language (Page property) Every page that is handled by Babel (those who are descendants of root pages that you choose on Babel module's settings page) will have a language property that returns a Language object that they are assigned to. It is determined based on under which rootParent the $page lives; Syntax $page->language; Return Language object. translation (Page method) This method returns the page that was assigned as a translation for the given $language. Syntax $page->translation($language); Arguments The $language argument could be either a string (the name of the language), an integer (the id of the language) or a Language object itself. Throws WireException if the language is not found or isn't handled by Babel. Return The method returns a Page object or NullPage if the translation is not available. translations (Page method) This method will return the pages that were assigned as a translation for all $languages that are available for that page. Or an empty PageArray if no translations are available. Syntax $page->translations(); Return Returns PageArray. addTranslation (Page method) This method will create a translation link from $page to $otherPage. Syntax $page->addTranslation($otherPage[, $overwrite]); Arguments The $otherPage argument should be a Page object. The language of the page will be determined by Babel itself based on under which language section the page is located. The $overwrite argument is optional and has three case scenarios: If omitted the reverse link of the translation will be created only if the $otherPage does not have a translation link for the $page->language. If set to true the reverse link will be overwritten even if $otherPage does have a translation link for the $page->language. If set to false the reverse translation link will not be created even if the $otherPage does not have any translation links. Return boolean if the translation link/s is/are created successfully or not. removeTranslation (Page method) The method removes a translation link between $page and $otherPage. Syntax $page->removeTranslation($language[, $remove]); Arguments $language (string|integer|Language) The language link you wish to remove. $remove (boolean) If there is a reverse link that points back from the translation to this page, should Babel remove it too. Default is false. Throws Throws WireException if the language couldn't be found or is not handled by Babel. Return boolean If the removal of the translation link/s is/are successful. closestParentTranslation (Page method) Returns the translation of the closest translated parent of the page. Syntax $page->closestParentTranslation($language); Arguments $language (string|integer|Language) The language for which you want a translation for. Throws Throws WireException if the language couldn't be found or is not handled by Babel. Return Page object. getRoot (Babel method) Returns the rootPage of the language. The one you have assigned in the module settings page. Syntax $modules->get('Babel')->getRoot($language); Arguments $language (string|integer|Language) Throws Throws WireException if the language couldn't be found or is not handled by Babel. Return Page object. translatable (Babel method) Tells if a page is translatable via Babel or not. Syntax $modules->get('Babel')->translatable($page); Arguments $page is a Page object. The page you want to check on. Return boolean If the page is translatable or not. getTranslated (Babel method) Returns a PageArray of translated pages. Syntax $modules->get('Babel')->getTranslated($fromLanguage, $toLanguage[, $limit[, $pageNum]]); Arguments $fromLanguage (string|integer|Language) The language from which the translation is. If omitted (or null given) then all the translation from all languages will be considered. $toLanguage (string|integer|Language) The language to which the translation is. If omitted (or null given) then translation to all languages will be considered. $limit is the number of pages you want to receive. Default is 50. $pageNum is the page number. Use for pagination of the returned PageArray. Default is 1. Throws Throws WireException if the language couldn't be found or is not handled by Babel. Return PageArray. getUntranslated (Babel method) Returns a PageArray of pages that are not translated to one or the other language. Syntax $modules->get('Babel')->getUntranslated($fromLanguage, $toLanguage[, $limit[, $pageNum]]); Arguments $fromLanguage (string|integer|Language) The language from which there is no translation. If omitted (or null given) then all the untranslated pages from any language will be considered. $toLanguage (string|integer|Language) The language to which there is no translation. If omitted (or null given) then untranslated pages to any language will be considered. $limit is the number of pages you want to receive. Default is 50. $pageNum is the page number. Use for pagination of the returned PageArray. Default is 1. Throws Throws WireException if the language couldn't be found or is not handled by Babel. Return PageArray. babelHomePage ($config property) Reference to the home page. This is usually one of the pages that you chose in the module settings. Syntax $config->babelHomePage; The babelHomePage is determined based on: the path that user has entered... if not available then the session is checked... if not available then it defaults to the core LanguageSupport module's default language; Usage Tips If your site structure is the way it looks like it is shown above. Your root page usually won't ever render. Whenever a user enters your site at the `/` path you will redirect him to one of language root pages. Here is how I suggest you to do that in your root.php template file. $session->redirect($config->babelHomePage->url, false); that's pretty much everything you need to have in your root.php file. To display links for each language homepage... $home = $config->babelHomePage; $homePages = $home->translations()->and($home); echo "<ul>"; foreach ($homePages as $p) { $title = $p->language->title; echo "<li><a href='$p->url'>$title</a></li>"; } echo "</ul>"; To display links for each translation of the current page... echo "<ul>"; foreach ($page->translations() as $p) { $title = $p->language->title; echo "<li><a href='$p->url'>$title</a></li>"; } echo "</ul>"; ProcessBabelTranslate Babel comes with very useful admin helper. You can link pages as a translation for each other. You can create translation page if there isn't one yet. There is small indicators on page tree that shows which pages are translated to what languages. And you get a Babel Tanslate page where you can quickly find all the translated and untranslated pages accross your site. See the screenshots below... Settings page Translation indicators Quick action button Quick modal translate form Tab translate form ProcessBabelTranslate page Go ahead and try it out. This is my first module to publish. Please tell me if something need to be added, changed, removed...
  12. There is a good Map Marker by Ryan.
×
×
  • Create New...