Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 10/03/2018 in all areas

  1. Building your very own custom Fieldtypes in ProcessWire seems to be hard, but it actually is not, once you get the concept. In this post I'll share a simple and as minimalistic module as it can get that everybody can use as a boilerplate for his own Fieldtypes. A Fieldtype that does not store any information in the database A Fieldtype that stores information in the database (to be done) Make your Fieldtype configurable 1. A Fieldtype that does not store any information in the database Some of you might know the excellent RuntimeMarkup module by @kongondo. I've used it a lot in the past, but I get more and more into developing custom fieldtypes rather than hacking the runtime module to my needs. That has several advantages, but it has also one major drawback: It is always a pain to setup a new Fieldtype, because there are lots of methods (see the base class /wire/core/Fieldtype.php) and you have to know which methods you need, which ones you have to remove and adopt etc.; Not any more! Ryan has developed a showcase module (the Events Fieldtype) to learn from, but when I first peaked into it, it felt quite complex and I thought it would be a lot of effort to learn Fieldtype development). There are also some easy and small Fieldtypes to learn from, like the FieldtypeCheckbox. But all of them require a good understanding of what is going on, you need to modify existing config inputfields that might have been added to that fieldtype and afterall it's not as easy as it could be. With my new approach I plan to use a boilerplate fieldtype to start from (in OOP terms to "extend" from) and only change the parts i need... More on that later. Here is the boilerplate module with some debugging info to illustrate the internal flow on the tracy console: See the module in action in the tracy console ( @adrian has done such an amazing job with that module!!!): The code should be self-explaining. What is interesting, though, is that after the ### getUnformatted ### dump there is only one call to "___formatValue". All the other calls (loadPageField, wakeupValue and sanitizeValue) are not executed because the value is already stored in memory. Only the formatting part was not done at that point. With that concept it is very easy to create your very own custom Fieldtypes: <?php namespace ProcessWire; /** * Demo Fieldtype Extending the Boilerplate Runtime Fieldtype * * @author Bernhard Baumrock, 03.10.2018 * @license Licensed under MIT * @link https://www.baumrock.com */ class FieldtypeDemo extends FieldtypeMarkup { public static function getModuleInfo() { return [ 'title' => 'Demo', 'version' => '0.0.1', 'summary' => 'Demo Fieldtype', 'icon' => 'code', ]; } /** * convert the wakeupValue to the given format * eg: convert a page object to a string */ public function ___formatValue(Page $page, Field $field, $value) { $value = parent::___formatValue($page, $field, $value) . " - but even better!"; d($value, '___formatValue --> convert to whatever format you need'); return $value; } } Notice the change "but even better" in the last two dumps. I think it can't get any easier, can it?! ? I'll continue testing and improving this module, so any comments are welcome! 2. A Fieldtype that stores information in the database See this module for an easy example of how to extend FieldtypeText:
    12 points
  2. I'm sure you'll get more elaborate answers, just a short question: Do you know about bootstrapping pw? https://processwire.com/api/include/
    6 points
  3. Are you saying that I can just find a right ProcessWire and include its index.php to my web app, and I have full access to its pages and users? I can't but wonder and love the chances of this platform. Thanks! This is so awesome work.
    5 points
  4. Sure - don't think I'll bother with the title attribute here though - it should be obvious enough. I also changed the order so the more important/relevant ones are on the left, although I am not really sure where "list" belongs ?
    3 points
  5. This is the sole reason also I'm stuck in prehistoric emacs setup, to easily work on servers, always a command away from connecting to a server and opening a folder. OMG it's finally here!! Gonna try this ASAP. https://marketplace.visualstudio.com/items?itemName=Kelvin.vscode-sshfs#review-details EDIT: OMG it works wonders, love this.
    3 points
  6. I'd love some help ? If people have ideas for other panels that would be brilliant. It's really very simple to get a panel working and what you do with it is up to you. Maybe I'll add this to the docs site (https://adrianbj.github.io/TracyDebugger/#/) at some point, or maybe someone could do that for me, but here are the really quick basics. Create a new file under the panels subdirectory named to match the name of your new panel, eg: MyNewPanel.php In that file have a class MyNewPanel that extends BasePanel, eg: class MyNewPanel extends BasePanel { Add getTab() method optional isAdditionalBar() method to check if the current call to the panel is from an AJAX or Redirect debug bar. Some panels are not relevant for these bars, so you can check that and return if you wish. timer() method to check how long it takes to generate this panel. return a span with title tag (for mouseover of the panel icon in the debug bar) with the SVG for the icon and a label. It's up to you to assign the SVG to that $this->icon variable. public function getTab() { if(\TracyDebugger::isAdditionalBar()) { return; } \Tracy\Debugger::timer('myNew'); return ' <span title="My Panel"> ' . $this->icon . (\TracyDebugger::getDataValue('showPanelLabels') ? ' My Panel' : '') . ' </span>'; } Add getPanel() method if this panel does work with additional bars, then check for this and add the name of the bar in parentheses in the <h1> title output should all be contained in a tracy-inner div use generatePanelFooter to create the ms/kb values in the footer of the panel. The last parameter (optional) is for a hash link to the docs website return - parent::loadResources() actually currently returns nothing but it's in the BasePanel class and may be used again at some point, so should be included in the return. The minify() method is not mandatory but I use it in some panels with a lot of embedded JS / HTML. Note that it's very rudimentary and currently is broken by inline comments in $out so be careful. public function getPanel() { $isAdditionalBar = \TracyDebugger::isAdditionalBar(); $out = ' <h1> <a title="My New"> ' . $this->icon . ' My New </a>' . ($isAdditionalBar ? ' ('.$isAdditionalBar.')' : '') . ' </h1> $out = '<div class="tracy-inner">'; $out .= 'whatever you want output in the panel'; $out .= \TracyDebugger::generatePanelFooter('myNew', \Tracy\Debugger::timer('myNew'), strlen($out), 'myNew'); $out .= '</div>'; return parent::loadResources() . \TracyDebugger::minify($out); } You have access to these color constants from the main \TracyDebugger class: const COLOR_LIGHTGREY = '#999999'; const COLOR_GREEN = '#009900'; const COLOR_NORMAL = '#354B60'; const COLOR_WARN = '#ff8309'; const COLOR_ALERT = '#cd1818'; You can access module config settings with: \TracyDebugger::getDataValue('settingName'); Once the panel is built, you can add it to Tracy here: https://github.com/adrianbj/TracyDebugger/blob/dd617b8ca8f450b8891ecacaef2b3949698fc126/TracyDebugger.module#L139-L169 That's a very rough first draft of what needs to happen. I think the best place to start is probably the MethodsInfoPanel.php file because it's so simple. This process has reminded me of just how messy some things are ?
    2 points
  7. snippet mania continues ? "Add hook with separate method": { "prefix": "hook", "body": [ "\\$this->wire->addHook$1('$2', \\$this, '$3');$0", "/**", " * $4", " */", "public function $3(HookEvent \\$event) {", " $5", "}", ], "description": "Add hook with separate method" }, "Add hook with closure": { "prefix": "hook", "body": [ "\\$this->wire->addHook$1('$2', function(HookEvent \\$event) {", " $0", "});", ], "description": "Add hook with closure" },
    2 points
  8. Although in some cases, it also depends on the 'theme' you are using that IDE ?
    2 points
  9. I liked the previous colored version where it was more obvious who can or cannot do what. I would perhaps try making the X icons 50% transparent or so to separate things better (or remove entirely?). Another idea is that on clicking on the table would toggle the icons visibility, so eg it would load with no X icons but on click they would appear and the check icons would disappear. Or perhaps just use hover for inverting the icons' visibility so no need to use js? How about removing the -able endings in the column headers to make it more compact? You can add the original text as a title attribute to keep them too.
    2 points
  10. snippets are awesome! thx @kongondo, 2 more ? "Input get Variable": { "prefix": "get", "body": "\\$this->wire->input->get->$0", "description": "Input get Variable" }, "Input post Variable": { "prefix": "post", "body": "\\$this->wire->input->post->$0", "description": "Input post Variable" },
    2 points
  11. Boolean logic says that, if you want to negate a compound term, you need to negate each individual term AND change the operator. This is commonly referred to as De Morgan's law. !(a and b) = !a or !b Thus, you only need to change the and to or in your if clause: <?php if($item->size->value != 'half' || $item->prev()->size->value != 'half'): ?>
    2 points
  12. This module adds CSV import and export functionality to Profields Table fields on both the admin and front-end. http://modules.processwire.com/modules/table-csv-import-export/ https://github.com/adrianbj/TableCsvImportExport Access to the admin import/export for non-superusers is controlled by two automatically created permissions: table-csv-import and table-csv-export Another permission (table-csv-import-overwrite) allows you to control access to the overwrite option when importing. The overwrite option is also controlled at the field level. Go to the table field's Input tab and check the new "Allow overwrite option" if you want this enabled at all for the specific field. Please consider limiting import overwrite option to trusted roles as you could do a lot of damage very quickly with the overwrite option Front-end export of a table field to CSV can be achieved with the exportCsv() method: // export as CSV if csv_export=1 is in url if($input->get->csv_export==1){ $modules->get('ProcessTableCsvExport'); // load module // delimiter, enclosure, file extension, multiple fields separator, names in first row $page->fields->tablefield->exportCsv('tab', '"', 'tsv', '|', true); } // display content of template with link to same page with appended csv_export=1 else{ include("./head.inc"); echo $page->tablefield->render(); //render table - not necessary for export - just displaying the table echo "<a href='./?csv_export=1'>Export Table as CSV</a>"; //link to initiate export include("./foot.inc"); } Front-end import can be achieved with the importCsv() method: $modules->get('TableCsvImportExport'); // load module // data, delimiter, enclosure, convert decimals, ignore first row, multiple fields separator, append or overwrite $page->fields->tablefield->importCsv($csvData, ';', '"', true, false, '|', 'append'); Please let me know if you have any problems, or suggestions for improvements. Enjoy!
    1 point
  13. Some time ago I created a site profile for creation of a REST API with ProcessWire. Since I kept struggeling with updating stuff between different projects which use this, I decided to convert it into a module. It is now ready for testing: https://github.com/thomasaull/RestApi Additionally I added a few small features: automatic creation of JWT Secret at module install routes can be flagged as auth: false, which makes them publicly accessible even though JWT Auth is activated in module settings To check things out, download and install the module and check the folder /site/api for examples. If you find any bugs or can think of improvements, please let me know!
    1 point
  14. @bernhard, you can actually remove a few more methods from such a fieldtype - FieldtypeFieldsetOpen is a good one to refer to for a fieldtype that doesn't store anything in the database. A while ago I made a simple runtime-only fieldtype that generates inputfield markup from PHP files in a subfolder within /site/templates/ - sort of like a stripped-back version of RuntimeMarkup without any config fields in admin. It was just intended for use in my own projects and I didn't think it was worth announcing publicly seeing as we already have kongondo's module, but I've moved it to a public repo in case it is interesting for you to take a look at: https://github.com/Toutouwai/FieldtypeRuntimeOnly
    1 point
  15. 1 point
  16. Can confirm we've run into this same issue with the latest Bootstrap, latest PW and latest jQuery. We're currently doing this to ensure latest jQuery for the public and the compatible older version for editors. <?php //Load older version of jQuery for front end editor if ($user->isLoggedin()) { echo '<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>'; } else { echo '<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>'; } ?>
    1 point
  17. My vote would be not to colour the cells at all, or use a really light difference between the two because, as Bernhard already pointed out, there is no correct answer here - sometimes you want a role to have a permission - in which case the "tick" mark is correct - and sometimes you don't, in which case the "cross" is correct. @adrian there is a "Note" colour from the diagnostics panel that might work as a possibility here. Edited to add: just read the updates on empty cells for no-access. Even better!
    1 point
  18. That's a good question! When I developed this module I didn't had FormBuilder in hand. Now that I have a copy of this module, I will try to see if it works out of the box tomorrow. Stay tuned !
    1 point
  19. No issues for the moment, except can't get autocompletion to work :D. And yes @bernhard, it is a ProcessWire website with the wire folder and all but I'm guessing it might be the context in which i'm editing (SSH FS) and I'm actually loading as root a public_html with a lot of websites underneath it.
    1 point
  20. Everything works great here so far. I'm doing authentication with ssh keyfiles generated via git bash: https://git-scm.com/book/en/v2/Git-on-the-Server-Generating-Your-SSH-Public-Key These are my settings: The extensions do different things (as far as I understood)! FFHFS includes the file system of the remote server into your workspace. This is great to edit remote files on the fly. I just open the connection to my remote server, browse the tree down from the initial start at /var/www/vhosts, edit the file and save it. Perfect! The other extension is nice to connect to the server in the terminal. That can be handy to do a htop or to watch logfiles (tail -f /your/file): Left = vscode connected to my server, right = tracy console on a remote website using the file log function l(). That is great for monitoring resource intensive tasks like huge imports.
    1 point
  21. Same here!! Awesome!! This makes vscode even more brilliant ??? Let's continue to discuss this in the vscode thread:
    1 point
  22. Yeah, I actually think that is probably cleanest - thanks! awesome! thx ? Also, your Tracy Debugger module is an all-in-one Swiss Army Knife module to support development in general, so this feature would also be welcome. While I agree that it would be welcome I have to say that I haven't had a need for this module yet and will probably not have in the near future. I agree that it makes sense to integrate some modules into tracy, but I don't think it's a good idea to leave adrian alone with that effort. Even though he seems to be similar to ryan from a productivity point of view (do those two ever sleep? ?? ). I've done a little contribution once (field code) and it was not that hard. But maybe @adrian you could write up a little tutorial to show us how we can contribute to tracy. How everything plays together, what helpers are there, what css classes you use in general (or how we can inspect all that). Something like a quickstart of tracy extension building. Maybe this could make tracy more of a teamwork than an (absolutely awesome) one-man-show? Maybe tracy could even be built a little differently to support 3rd party modules. Just like you did recently with the admin actions module (https://processwire.com/talk/topic/14921-admin-actions/?do=findComment&amp;comment=173496). I'm not requesting this, I'm just thinking out loud here. Maybe I should - I have on occasion, but maybe I should more often! It would then also make sense to streamline the way of collaboration and have a standard workflow centralized on git.
    1 point
  23. Thanks, I think it's fine now (means I'm outta ideas :))
    1 point
  24. I'll need to think about this some more - I feel like we are starting to get into the territory of this module: http://modules.processwire.com/modules/process-access-overview/ which is not really the goal here, or at least it wasn't. I'll let you guys chime back in on what you think would actually be most useful. @LostKobrakai might not want to take his module any further, he also writes: Also, your Tracy Debugger module is an all-in-one Swiss Army Knife module to support development in general, so this feature would also be welcome.
    1 point
  25. Anyone use Regex search/replace in VSC code? This little guy will cleanup after you are done with your Tracy bd dumps (I'm no Regex guru, so test carefully first!). bd\(.*\);$
    1 point
  26. Not sure. Didn't know ACE even supports snippets! Crazy ? Personally I don't use the file editor at all (yet?). I use the console a lot, but would have never needed one of those snippets inside the console (for example the module snippet here https://processwire.com/talk/topic/17550-visual-studio-code-for-processwire-developers/?do=findComment&amp;comment=173964 is mainly because of the intellisense hint, but we don't have that in ace, do we?). What I do a lot in the console is looping over pagearrays, so that could be a nice first testsnippet ?
    1 point
  27. Clever trick with the double cursor/placeholder ?
    1 point
  28. What's your use case? Why is this important? If we got a better picture, we can probably suggest an alternative. Welcome to the forums ?
    1 point
  29. Yeah, I actually think that is probably cleanest - thanks! Maybe I should - I have on occasion, but maybe I should more often!
    1 point
  30. Exactly that. It's great when you have a big messy spreadsheet and you just want to grab selections of data to add to the Table.
    1 point
  31. Just popping in to say thanks for this awesome module! The "Paste in CSV Data" field saved me a heap of time today.
    1 point
  32. I would also like sqlite for reasons of easier local development and portability.
    1 point
  33. Ok, I have added this functionality to the RequestInfo panel like I suggested. This keeps things simple and always available. I got rid of all the background coloring - it's really not needed and I prefer the striped rows for clarity of info for each row. Current user is on the first row (and bolded to stand out) so if you're using the User Switcher panel you can quickly get all the details for that current user. I have a few other things in the works, but will commit this shortly.
    1 point
  34. I recently tend to do this, don't know about any best practises, though: That's the only thing where I'm not 100% happy so far. The available plugins that I tried are all somewhat clumsy/bloated/complicated. When I need to edit files directly I browse my server with WinSCP and then I can just double-click the file and it opens in VSCode. I can then edit and save this file from inside VScode and it gets uploaded automatically. For all other edits I switched to a git-setup, so I don't need direct edit via FTP any more. Meanwhile we also have Tracy+File Editor Panel for quick on-demand server edits.
    1 point
  35. I strongly vote against using the red color at all. IMHO having "no access" colored red is wrong, if you want the role not to have access! So it would be indicating a problem where everything is actually fine.
    1 point
  36. Ryan. Sorry to hear that. I hope you heal up quick. Drop a line to let us know you are OK.
    1 point
  37. Another idea for you: Would it be possible on the Dumps and Dumps Recorder panels to auto expand the dump if there is only 1 dump? That way someone doesn't have to click the plus sign or arrow to open the dump every-time the page is refreshed? Currently by default it is always collapsed. No worries if you can't, just a suggestion. Appreciate all you do.
    1 point
  38. created another useful snippet to reset the admin password: "Reset Admin Password": { "prefix": "reset", "body": [ "\\$admin = \\$users->get(41);", "\\$admin->setAndSave('pass', '$1');", "die(\"admin url = {\\$pages->get(2)->httpUrl}, admin username = {\\$admin->name}\");", ], "description": "Reset Admin Password" },
    1 point
  39. Hi @Sevarf2 Probably it's better this one: $wire->addHookAfter('LoginRegister::buildLoginForm', function($event) { $form = $event->return; $form->description = false; // Remove the description foreach ($form->children as $field) { // loop form fields if($field instanceof InputfieldSubmit) { // if we reach the submit button then $field->value = 'My Submit'; // change the value } } $event->return = $form; }); Probably me too later this week I will try to use, I think this could works. Take a look in the 1° page of this post there are also other part of code that maybe can help you.
    1 point
  40. Offtopic: if I will have some time I will add a similar feature to aos. The reason I haven't done this already is that never had the need for a color picker in the admin. This is the js I plan to use: https://github.com/narsenico/a-color-picker
    1 point
  41. Just keep in mind to maybe also check for a cookie or something, otherwise this will prevent users from manually switching to another subdomain / language.
    1 point
  42. Last night my cat bit my hand for no apparent reason while he was sitting in my lap. He's a very friendly cat, but also very old and I think may be getting a little senile. It was a deep bite, though didn't seem like all that big of a deal. But this morning my hand was hurting pretty bad, then it swelled up, and then a swelling red line appeared on my skin that went from my hand to my shoulder. I went to the doctor and he said it was a bad one, and if I hadn't come in today I would have been in the hospital tomorrow. Apparently cats have some mean bacteria in their teeth and these kinds of cat bites can get pretty bad, quickly. They shot me with a bunch of antibiotics and now I've got to go see another doctor and get an x-ray because they think that there's a possibility the cat's tooth broke off and may be stuck inside my hand (I hope not!). If the antibiotics do their thing, all should be fine in a few days. I'd planned on writing a blog post today about ProcessWire 3.0.115, but it looks like that's not going to happen (and one of my hands doesn't work so well), so I'll write about it next week in combination with 3.0.116 updates. But if you want to see what's new in 3.0.115 before that, be sure to check out the dev branch commit log. Thanks for reading and have a great weekend!
    0 points
  43. Dollar street ? Central bank prints Dollars like paper, banks lends Dollars just with digital numbers in a computer. Lol you don´t hear that on TED. Back to the website. Looking in the Page Source at the assets paths this site could have been made with Processwire, not sure. They used bootstrap 3.3.7 for the css layout. Looking at the header, the website doesn't inform about their real goal, but showing a truck load full of pictures. Is it just me, or does the website inform where the donation money is going ? Just my 5 cts , peace out ✌️
    0 points
×
×
  • Create New...