-
Posts
6,674 -
Joined
-
Last visited
-
Days Won
367
Everything posted by bernhard
-
Cat bite? ???
-
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:
- 17 replies
-
- 19
-
-
Is it possible to check if the password is correct without PW?
bernhard replied to anttila's topic in General Support
I'm sure you'll get more elaborate answers, just a short question: Do you know about bootstrapping pw? https://processwire.com/api/include/ -
It does not work in general or when using SSH FS? I guess it is not possible to work via SSH FS at all, because the extension indexes all LOCAL workspace files on startup and then creates the intellisense. Thats the same with things like the "find in folder" feature. That's why I prefer to develop locally and not remotely over FTP/SSH like I did some months ago. Combining it with all the great git support of VSCode it's a great environment ?
- 246 replies
-
- visual studio code
- vsc
-
(and 2 more)
Tagged with:
-
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.
- 246 replies
-
- 1
-
-
- visual studio code
- vsc
-
(and 2 more)
Tagged with:
-
Same here!! Awesome!! This makes vscode even more brilliant ??? Let's continue to discuss this in the vscode thread:
-
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&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.
-
Sure! I think we just have to start with one. All the others will come up automatically while we are developing. At least it is like this for me while working with vscode ? Knowing about the snippets I just create one whenever I come over something that I need over and over again. --- Back to VSCode --- Thx to @elabx I installed https://marketplace.visualstudio.com/items?itemName=Kelvin.vscode-sshfs#overview and it's absolutely brilliant. Just configure your remote servers and login easily from the command panel: Or via the GUI: I also installed this extension to open the terminal of my remote servers directly in vscode: https://marketplace.visualstudio.com/items?itemName=seanchann.sshlogin All those little tweaks of the last days makes me a lot more productive. And it's a lot more fun. Thx to everybody for the fruitful discussion! ?
- 246 replies
-
- 1
-
-
- visual studio code
- vsc
-
(and 2 more)
Tagged with:
-
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&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 ?
- 246 replies
-
- 1
-
-
- visual studio code
- vsc
-
(and 2 more)
Tagged with:
-
Yes, that's handy ? If you add the "HookEvent" type definition to the parameter you even get intellisense:
- 246 replies
-
- visual studio code
- vsc
-
(and 2 more)
Tagged with:
-
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" },
- 246 replies
-
- 3
-
-
-
- visual studio code
- vsc
-
(and 2 more)
Tagged with:
-
Do you have the wire folder in your project?
- 246 replies
-
- visual studio code
- vsc
-
(and 2 more)
Tagged with:
-
I vote for striped rows, no red, no green, just set the X to invisible or light grey. Checkmark means access, empty cell means no access. No warning colour but still easy to distinguish (better than without any colouring). @adrian why don't you create a temporary branch for such updates? We could then play around and give feedback or prs. Why sending zip files around?
-
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.
-
I think it's good to have some color. What about the colors of the console - active = white, inactive = light blue: Understand. Thx ?
-
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" },
- 246 replies
-
- 2
-
-
- visual studio code
- vsc
-
(and 2 more)
Tagged with:
-
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.
-
Better imho! I think it could even be grey instead of orange. I'll play around with it one day, but atm I'm busy with other stuff and don't need to care about permissions a lot ? Maybe @tpr comes up with a good suggestion... This isn't about permissions in the sense you are talking about. It's just for these page permissions: https://github.com/processwire/processwire/blob/341342dc5b1c58012ae7cb26cffe2c57cd915552/wire/core/Page.php#L88-L107 Maybe it needs to be reimagined, but that was my initial goal for this. What does everyone think? Oh. I also thought it would list all available permissions. Didn't know about that one. You are absolutely right. Anyhow, it was just an idea. Personally I don't have a need at all for such a panel, but I'm quite sure it can be very handy to have one day...
-
VSCode in my home.php template file (note the marked php start and end tag because I had my cursor there which is not visible in the pic): That's ok because the green parts are just strings for your IDE! Same with VSCode: I think you should have a look at https://processwire.com/api/ref/files/render/g/ Take this example: And in your invoicetemplates.php file you could have clean code just like this: Why not give VSCode a try? ?
-
Maybe you want to paste code snippets and a screenshot to help us understand your problem better? I'm using VSCode and it looks like this: Another example with a multiline concatenated string: And another one appending some infos to a rendered field value:
-
Are you talking about a link to the docs or about shortcut links to the settings page of the template where the admin can adjust those permissions? The latter would be great! Maybe there could also be a section where it shows which template setting is responsible, eg: path | template | active -----------------|--------------|-------------------------------- / | home | yes /foo | basic-page | yes /foo/bar | whatsoever | no (inherited from basic-page) The template strings could be linked to the access tab of the template settings. Not sure how complicated that would be to implement, but I think it could be helpful ? +1 for some more thoughts on the colors! I think the red is too loud. It's not a warning imho - it's just telling there is no permission. I think the red could be removed completely. I'm fine with the green - although I think it could also be more quiet...
-
Hi, seems you need something VERY similar to one of my projects: https://www.grafikgesellen.at/textilien/gwaund-fuer-oesterreicha/landkarten-shirt/ Is it a commercial project? If you are interested in a siteprofile just send me a pm.
-
That's because of the way markup regions work: See the link to the github issue and ryans explanation. +1 for using Tracy, like Robin mentions in the post.
-
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" },
- 246 replies
-
- 2
-
-
- visual studio code
- vsc
-
(and 2 more)
Tagged with: