Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 11/23/2021 in all areas

  1. In other news: Color-coding content blocks is such a great addition. Even those who don't use the backend that often find the right spot way easier now. Thanks @Ivan Gretsky for the idea and @ryan for adding this to the latest dev branch.
    6 points
  2. Confirming that the expressions of interest is now closed. I will collate the responses and get back to all who registered. I am working on a getting started frontend that will help with the testing. I am also working on a minimal API documentation to help you put it all together. Thanks to all who have responded and/or have an intention to support this work in the future ?.
    4 points
  3. Good ideas. I think both of the things mentioned (autosave only while live preview active) and some kind of obvious toggle/checkbox would both be good to have. I'll plan to add.
    4 points
  4. I'd like to share how I integrated stripe in PW.. and it works!! ?‍♂️ :-D! FORM in product page: <div style='display:<?php if ($page->Mostra1 == 1) echo "block"; echo "none";?>'> <form action='<?php echo $pages->get('template=create-checkout-session')->url; ?>' method='POST' > </form> <?php $myForm1 = " <form action='{$stripe->url}' method='post'> <button type='submit' id='checkout-button' >Acquista</button> </form>"; echo $myForm1;?> </div> and this is the 'create-checkout-session' template: <?php include 'init.php'; Stripe\Stripe::setApiKey('xxxxxxxxxxxxxxxxxx'); header('Content-Type: application/json'); $YOUR_DOMAIN = 'https://www.xxxxxxxx.it/'; $checkout_session = \Stripe\Checkout\Session::create([ 'shipping_address_collection' => [ 'allowed_countries' => ['IT'], ], 'shipping_options' => [ [ 'shipping_rate_data' => [ 'type' => 'fixed_amount', 'fixed_amount' => [ 'amount' => 700, 'currency' => 'eur', ], 'display_name' => 'Standard', // Delivers between 5-7 business days 'delivery_estimate' => [ 'minimum' => [ 'unit' => 'business_day', 'value' => 5, ], 'maximum' => [ 'unit' => 'business_day', 'value' => 7, ], ] ] ], [ 'shipping_rate_data' => [ 'type' => 'fixed_amount', 'fixed_amount' => [ 'amount' => 1000, 'currency' => 'eur', ], 'display_name' => 'Celere', // Delivers in exactly 1 business day 'delivery_estimate' => [ 'minimum' => [ 'unit' => 'business_day', 'value' => 1, ], 'maximum' => [ 'unit' => 'business_day', 'value' => 3, ], ] ] ], ], 'line_items' => [[ # Provide the exact Price ID (e.g. pr_1234) of the product you want to sell #'price' => 'price_1JyahSFL4ZyLp1tjGGqakV4Z', #'price' => $price, 'name' => $session->get(prod), 'amount' => $session->get(price), 'currency' => 'eur', 'quantity' => 1, ]], 'mode' => 'payment', 'success_url' => $YOUR_DOMAIN . 'grazie/', 'cancel_url' => $YOUR_DOMAIN . 'pagamento-rifiutato/', ]); header("HTTP/1.1 303 See Other"); header("Location: " . $checkout_session->url); I used: $session->set(prod, "$page->title"); >>> 'name' => $session->get(prod), I hope this stuff can be useful for someones!
    3 points
  5. Fieldtype modules Not really a tutorial, but a bunch of stuff I learnt in building a fieldtype module (FieldtypeMeasurement). That module is used as a starting point for many of the examples. Happy to take corrections and improvements ? Basics For a (full-featured) module, you actually need two module files: FieldtypeModuleName.module; and InputfieldModuleName.module The Fieldtype module defines the general settings for the fieldtype (how it appears in the setup->field page), together with how it interacts with the database, while the Inputfield module defines how the field appears when editing it in a page. In addition, for complex fields, you can define a class to hold your field values in an object. This allows you to provide custom methods for use in the API. Otherwise you can store field values as any existing type or ProcessWire object The chart below summarises the interactions of these elements and the subsequent sections describe the methods in more detail. Fieldtype Module The important methods are described below. __construct() Generally not much is required here (apart from parent::__construct();). If you have a php script with the field object then include it (require_once() ). SQL database interaction getDatabaseSchema(Field $field) This is essential. It states what data will be saved to the SQL database (via the sleepValue function - see below). An example is: public function getDatabaseSchema(Field $field) { $schema = parent::getDatabaseSchema($field); $schema['data'] = 'double NOT NULL'; // value in base units $schema['magnitude'] = 'varchar(64)'; // value in current units - needs to be text to store composite values $schema['unit'] = 'text NOT NULL'; $schema['quantity'] = 'text NOT NULL'; return $schema; } 'data' is required and is a primary key field which means that 'text' cannot be used, although varchar(64) is OK. Often (as here) it would be a numeric field of some type. Other items can be defined as required. ___sleepValue(Page $page, Field $field, $value) This determines how the ProcesssWire field object is mapped to the SQL schema. You need to return an array where the keys are the elements defined in the schema, e.g.: $sleepValue = array( 'data' => $data, 'magnitude' => $magnitude, 'unit' => $value->unit, 'quantity' => $value->quantity ); return $sleepValue; ___wakeupValue(Page $page, Field $field, $value) This is basically the inverse of sleepValue - mapping the array from the database into the field object. In the example below, the field object (Measurement) extends WireData. Properties in WireData objects can be stored in the 'data' property via 'get' and 'set' methods. getBlankValue() (see next section) performs the initial setting of these - config values for the field (see below) can be set, but otherwise the settings are just placeholders. Properties set to a WireData object can also be set or accessed directly, like $item->property or using array access like $item[$property] public function ___wakeupValue(Page $page, Field $field, $value) { // if for some reason we already get a valid value, then just return it if($value instanceof Measurement) return $value; // start a blank value to be populated $measurement = $this->getBlankValue($page, $field); // if we were given a blank value, then we've got nothing to do: just return a blank Measurement object if(empty($value) || !is_array($value)) return $measurement; // create new Measurement object $measurement->quantity = $value['quantity']; // ... custom processing ... $measurement->baseMagnitude = $value['data']; if($value['unit']) { $measurement->unit = $value['unit']; $units = $measurement->getUnits(); if(array_key_exists($value['unit'], $units) && isset($value['magnitude'])) { $measurement->magnitude = explode('|', $value['magnitude']); } else { $measurement->magnitude = $measurement->baseMagnitude; $measurement->unit = $measurement->units->base; $this->error('... error msg ...'); } } else { //... } if(!is_array($measurement->magnitude)) $measurement->magnitude = [$measurement->magnitude]; return $measurement; } getBlankValue(Page $page, Field $field) This should return an empty item of the appropriate type. For instance, if your field object is an array, just return array(); If the field type is an object then you will need to return a 'new ObjectClassName()'. Pre-fill any config values from the Fieldtype settings but leave blank those which are set in the Inputfield, In the above example, the field object data was set as follows: public function getBlankValue(Page $page, Field $field) { /* @var $field FieldtypeMeasurement */ $measurement = new Measurement($field->quantity, null, []); if ($field->quantity) $measurement->set('quantity', $field->quantity); $measurement->set('magnitude', []); $measurement->set('shortLabel', null); $measurement->set('plural', null); return $measurement; } If your object has configurable fields that can be modified according to context (as defined in getConfigAllowContext() - see below), then you will need to deal with this in getBlankValue too, e.g. : public function getBlankValue(Page $page, Field $field): Measurement { //NB Field details may differ between templates so we need to get the field in context $context = ($page && $page->id) ? $field->getContext($page->template) : $field; ... $measurement = new Measurement($context->quantity, null, []); ... return $measurement; } But note that this does not completely deal with the situation where the field is in repeater matrix items where the types might have different contexts - there you might need: public function getBlankValue(Page $page, Field $field): Measurement { //NB Field details may differ between templates so we need to get the field in context $context = ($page && $page->id) ? $field->getContext($page->template) : $field; ... // if($page instanceof RepeaterMatrixPage) { // This does not always work - see edit note if($page->template->pageClass == 'RepeaterMatrixPage') { if($page->getField($field->name)) { $context = $page->fieldgroup->getFieldContext($field, "matrix$page->repeater_matrix_type"); } } ... $measurement = new Measurement($context->quantity, null, []); ... return $measurement; } See this post for more details. Configuration ___getConfigInputfields(Field $field) This defines how the Details tab in the field setup page will look. The best thing to do here is to find a fieldtype module that is similar to the one you want if you are uncertain. Broadly the process is: define the config object - $inputfields = parent::___getConfigInputfields($field); for each config item, use the appropriate input field, e.g . $f = $this->modules->get("InputfieldSelect"); assign the relevant attributes. $f->name = $f_name; is important as it enables the item to be subsequently referred to as $field->f_name in, for example, getBlankValue(). append each item ($inputfields->append($f);) and return $inputfields; ___getConfigAllowContext(Field $field) This determines if the above input fields are allowed to have unique values per Fieldgroup assignment enabling the user to configure them independently per template in the admin, rather than sharing the same setting globally. E.g. public function ___getConfigAllowContext(Field $field) { $a = array('quantity', 'units', 'hide_quantity', 'show_update'); return array_merge(parent::___getConfigAllowContext($field), $a); } In this example the settings 'quantity', 'units', 'hide_quantity' and 'show_update' can be varied in different template contexts. Link with the Inputfield module This is done with getInputfield(Page $page, Field $field) e.g.: public function getInputfield(Page $page, Field $field) { $inputfield = $this->wire('modules')->get('InputfieldMeasurement'); $inputfield->setField($field); return $inputfield; } If you want to reference the current page in the inputfield, you will also need to include $inputfield->setPage($page); If your fieldtype is an object and you want full context flexibility including for different repeater matrix item types, then you may need to use this: public function getInputfield(Page $page, Field $field): Inputfield { $inputfield = $this->wire('modules')->get('InputfieldMeasurement'); if($page->template->pageClass == 'RepeaterMatrixPage') { if($page->getField($field->name)) { $field_in_context = $page->fieldgroup->getFieldContext($field, "matrix$page->repeater_matrix_type"); if($field_in_context) { $field = $field_in_context; } } } $inputfield->setField($field); $inputfield->setPage($page); return $inputfield; } Inputfield Module __construct() Generally not much is required here (apart from parent::__construct();). If you have a php script with the field object then include it (require_once() ). Configuration ___getConfigInputfields() This is pretty much exactly the same construction as the similar method in the Fieldtype class. The only difference is that these settings will appear in the 'input' tab of the fieldtype settings, rather than the 'details' tab. ___getConfigAllowContext(Field $field) This is the equivalent to the Fieldtype::getConfigAllowContext() method, but for the "Input" tab rather than the "Details" tab. Input and output The key methods for this module are to render it from the fieldtype and database and to process the user inputs. ___render() $field = $this->field will have the field config settings from the fieldtype module. $this->attr('value') will have the current values for the field. If there is no current values then, if using a field object, you will need to create a new object, e.g.: if($this->attr('value')) $value = $this->attr('value'); // Measurement object else { $value = new Measurement(); } You can then use $field and $value to display the inputfield (which might be a fieldset) as required using the appropriate pre-existing inputfield modules. (Again, find an existing module that is similar, if you are uncertain). renderValue() This is required where the field is locked (not editable) and therefore render() does not apply. Get the value with $value = $this->attr('value'); and then apply the required formatting, returning the output string. ___processInput(WireInputData $input) Here you take the inputs and update the field values. As in render(), set $value = $this->attr('value') ; and then modify $value for the inputs. For example, set $name = $this->attr('name'); and then assign the inputs thus: $input_names = array( 'magnitude' => "{$name}_magnitude", 'unit' => "{$name}_unit", 'quantity' => "{$name}_quantity", 'update' => "{$name}_update" ); You can then loop through the inputs and carry out the required updates. The example below is slightly convoluted but illustrates this: foreach($input_names as $key => $name) { if(isset($input->$name) && $value->$key != $input->$name) { if($key == 'magnitude') { $input->$name = trim($input->$name); if(!is_numeric($input->$name)) { $magnitude = explode('|', $input->$name); $magnitude = array_filter($magnitude, 'is_numeric'); $value->set($key, $magnitude); } else { $value->set($key, [$input->$name]); } } else { $value->set($key, $input->$name); } $this->trackChange('value'); } } When all is done, return $this; Custom classes As mentioned earlier, for complex field types it may be useful to set up custom classes to hold the data. Typically a custom class would extend WireData, which is ProcessWire's class designed for runtime data storage. It provides this primarily through the built-in get() and set() methods for getting and setting named properties to WireData objects. The most common example of a WireData object is Page, the type used for all pages in ProcessWire. Properties set to a WireData object can also be set or accessed directly, like $item->property or using array access like $item[$property]. If you foreach() a WireData object, the default behaviour is to iterate all of the properties/values present within it. Do not declare any such properties in your class (or declare properties with the same name) otherwise you will end up with two properties, one in the 'data' array and one outside it and endless confusion will result. It is advisable to put any such classes in your own namespace. In that case, you will need to include 'use' statements in your script - e.g. use ProcessWire\{FieldtypeMeasurement, WireData}; use function ProcessWire\{wire, __}; and also include use statements in your module scripts, e.g. use MetaTunes\MeasurementClasses\Measurement;
    2 points
  6. Question to all of you... What about a setting that enables PageAutoSave O N L Y when in PreviewMode? I play a lot with Page Autosave + Live Preview but sometimes I'm just tackling my daily tasks and the auto-save feature is (kind of) too much as I start writing but can't finish the text due to a phone call, "writer's block" or my empty coffee cup. Yet the content was entered, saved and is available on the frontend for page visitors. Luckily only within a side project at the moment but still. I could enable the feature only for unpublished pages but most of the content that gets edited is already published and therefore live-content. I'm almost missing a setting like "enable autosave only when livepreview-window is active". What do you think?
    2 points
  7. Hi, I have multiple $pages->find() operations which result in multiple page ids. e.g.: $find1: 8044|10045|3702|11067 $find2: 2004|5421|9392 Next i'm searching these ids to get a new WireArray, which i can limit and paginate: $unifiedMatches = $pages->find("id=$find1|$find2, limit=$limit"); This works all as intended. The problem is, that this new collection of pages doesn't maintain the order of the ids in the selector. They are sorted by their id. $unifiedMatches: 2004|3702|5421|8044|9392|10045|11067 Is there a way to get the pages in the $unifiedMatches result in the order of the selector input? $unifiedMatches: 8044|10045|3702|11067|2004|5421|9392 Thanks!
    1 point
  8. OK. If the table is an invoice table, I presume then that you know which of the variants of this product was bought. For instance, Pro RTX Pro Pique Polo Shirt comes in several variants, Small x Lilac, Medium x Brown. In your first line then, you should know if it was Small x Lilac that was bought of Medium x Brown. All variants have IDs. This is the bit I don't get. In your Hook, you can autofill Size and Colour by grabbing the product variant using its ID. Is there a reason you cannot do that? Unless, these invoices are being created manually maybe off a phone order, in which case, the editor has no idea what the variant ID is :-). Sorry if I am taking you round in circles. Alternatively, I could have a quick look if a discrete temporary login to your site is possible.
    1 point
  9. Hi @Marco Ro. I have read this several times and I am not sure I understand it all. Could you please explain what you mean by a php page? Do you mean a PHP file? Secondly, what module is this? Is this a custom module you are developing, e.g., /site/MyModule/. Is it perhaps a Process Module? If so, by page, do you mean executeSomePage() in your custom Process Module? Are you talking about two servers talking to each other? How are you fetching the JSON? Are you accessing some API endpoint? Are you fetching the JSON using CURL? By 'another API call', do you mean a different (third) server? OK, this means whatever is trying to access your file inside your modules folder is forbidden to do so, which is expected, but dependent on where the call is coming from. I think if you could provide some code, illustration or clarifications to the above questions, we would be better placed to assist.
    1 point
  10. 1 point
  11. I agree that some sort of on-the-fly option to opt out of autosave would be essential. One option is what you suggest ("PageAutoSave O N L Y when in PreviewMode?") but maybe an on/off switch would be nice to have too (next to the page title or something like that). So I am thinking of not just one way to opt out temporarily but more than one way to suit "all needs". I do not have the time to test the autosave feature, so I cannot be more specific but the issue you are facing sounds quite reasonable and that is why I commented on it ;)
    1 point
  12. OK, we are getting warmer. A few questions: Pro RTX Pro Pique Polo Shirt: is that a product or a product variant? I guess the former though. If it is product, I am assuming it has variants? If it has variants, what do you want to display in the columns Size and Colour? Should they not display a single size and colour (e.g., Small and Lilac) respectively?
    1 point
  13. Nice overview! For full fledged field types, you'll often also want to implement Fieldtype::getConfigAllowContext and Inputfield::getConfigAllowContext. They return an array with the names of those config fields defined in their respective getConfigInputfields method that may be overridden in template or fieldgroup context. The Inputfield class by default returns these config fields: return array( 'visibility', 'collapsed', 'columnWidth', 'required', 'requiredIf', 'requiredAttr', 'showIf' ); So make sure to call parent::getConfigInputfields first, then add your own config inputs. A good example is how InputfieldText does this: public function ___getConfigAllowContext($field) { $a = array('initValue', 'pattern', 'placeholder', 'maxlength', 'minlength', 'required', 'requiredAttr'); return array_merge(parent::___getConfigAllowContext($field), $a); } Now the initValue, pattern, placeholder, maxlength, required and requiredAttr settings can be overridden in each template the field is used in.
    1 point
  14. For a customer I needed a bunch of pictures to make a mosaic in Photoshop (cropped as a square) ? 20 lines of ProcessWire "et voila": a folder full of first pictures of every page from a certain template. <?php namespace ProcessWire; // boot api include('index.php'); // find estates from web database $estates = $pages->find("template=archief-pand"); // if estates count not zero if(count($estates)){ // loop over estates ($e is single estate) foreach($estates as $e){ // if images not null if(count($e->images)){ // get first image of estate gallery $firstPic = $e->images->first(); // resize and crop image to square 800x800px $firstPic = $firstPic->size(800,800); // if picture not null then copy picture to folder propics if(!empty($firstPic)) copy($_SERVER['DOCUMENT_ROOT'].$firstPic->url, $_SERVER['DOCUMENT_ROOT'].'/propics/'.$firstPic); } } }
    1 point
  15. That's the Locality of Behaviour here ?. Cheap one, I know, sorry, I couldn't help myself. Any chance you could please give us your thoughts on this one? We have suggested onLoad and your example here on 3rd-party integration. Would you have other thoughts maybe? Thanks. Nice one! Yeah, Python has been getting all the love ?.
    1 point
  16. I am finishing the next release right now and will be pushing a new version. In this version you can customize all Fluency UI strings for any default language, using the translation service if desired.
    1 point
  17. I’m not quite sure if this is of interest for anyone and if this is the right forum for my post, but I got the client request to build a module extension for Fluency which translates all the text fields in a page with only one click. The module is not really ready for public (or the modules section), as it has no config page yet and was only tested in one ProcessWire installation, but maybe it is useful as a starting point for anyone who is in the same situation as me: https://github.com/robertweiss/ProcessTranslatePage The module checks for fluency-translate permissions and adds a ›Translate and save‹-button to the edit-page. It supports all core language fields, Repeater, FieldsetPage the pro modules Repeater Matrix, Combo and Functional Fields. Caution: for now, the (language-)settings have to be manually edited in the hookPageSave-Method (Lines 64–69).
    1 point
  18. Ryan might've had other reasons as well, but... this keeps the textformatter from making a mess out of user-generated content where video URLs could be used in links, within regular text, inside table cells, in image captions, etc. ? That being said, it'd be nice if the module provided a public method for converting known single video URL into an embed code. Currently it looks a little hacky: $url = '<p>https://www.youtube.com/watch?v=ytWz0qVvBZ0</p>'; $modules->get('TextformatterVideoEmbed')->format($url); echo $url;
    1 point
  19. @DV-JF, I thought that this module was too "minor" to belong in the modules directory, but I get that it makes it easier to find, install and update so I've added it now. It should get validated and appear in the directory soon.
    1 point
  20. 1 point
  21. The sorting of these queries is not really important. The important thing for me is, that the results from $find1 are in front of $find2. It's like a lazy weighted search, where I first search the titles of the pages for a keyword/phrase ($find1) and then search the other fields (body etc.) for the same keyword (excluding the ids from $find1). The logic here is, that pages, which have the keyword in their title, are more relevant/important than the other results and should come first.
    1 point
  22. Adminer is great, you can even paste the entire content of the file into a pw template and have it in the admin. This way it's protected with two passwords
    1 point
  23. I like this solution: $events1 = $pages->find("template=event, date>=today"); $events2 = $pages->find("template=event, date<=today, date_end>=today"); $events = $pages->find("id=$events1|$events2, sort=date, limit=15"); // now you can paginate $events
    1 point
×
×
  • Create New...