Jump to content

RockNette - Wrapper to integrate Nette Framework into ProcessWire


bernhard
 Share

Recommended Posts

The title might sound more exciting that it actually is. It's just a little helper module to keep things organized ? Basically it just saves you from finding the correct require_once("where/is/my/nette?") and, for a little extra security, it adds an .htaccess file to block all direct access to Nette source files.

 

Why?

Nette is an awesome framework with some awesome features/utilities that ProcessWire lacks. Creating separate modules and including Nette packages multiple times in those modules would not be efficient. RockNette makes it easy to store them in a central place.

 

Usage

You'll get all necessary instructions on the module information screen:

img

https://github.com/BernhardBaumrock/RockNette

  • Like 8
Link to comment
Share on other sites

Hi @Ivan Gretsky

Which links are broken?

Hm... Nette Forms... I really like one thing: Synched frontend + backend form validation. But on the other hand I really miss one thing: ProcessWire ? Especially hooks. In Nette there's nothing like hooks as far as I know. They do everything by extending base classes. This can be great for more complex modifications (that's why we now have the new Page classes in ProcessWire), but modifying just one single Inputfield of a Nette form was hard to impossible for me when I played around with it some time (years?) ago... That experience might be a little different know that I made quite some progress in OOP.

One thing I could also not get working was CSRF protection via Nette. So I implemented it using ProcessWire's internal feature: 

Yes... it's obviously been 2 years since I worked on that ? I need some forms on a new project, so I might have a look into a new Forms Module using the new RockNette concept and Nette v3.0

  • Like 1
Link to comment
Share on other sites

  • 1 month later...
  • 5 months later...

Hi eydun,

I thought it might make sense to be able to share the nette components across several modules. I'm not sure if that is the best approach. Another option would be to use composer in the root folder to load nette components (I think that would be the more standard way)!

I just didn't want to put it in the module itself because this would mean I'd need to update the modules with every update of nette...

  • Like 3
Link to comment
Share on other sites

  • 1 month later...

HI Bernhard,

Thanks for the module. Looks interesting and worth exploring. I am trying it out but running into a problem while using a rendering function for UIkit, adapted from the makeBootstrap4 one used on the Nette site as an example. I get the error: Call to undefined function makeUIkit(). Any idea where I may be going wrong. Thanks. 

namespace ProcessWire;

use Nette\Forms\Form;

function makeUIkit(Form $form): void
{
	$renderer = $form->getRenderer();
	$renderer->wrappers['controls']['container'] = null;
	$renderer->wrappers['pair']['container'] = 'div class="uk-margin"';
	$renderer->wrappers['pair']['.error'] = 'uk-form-danger';
	$renderer->wrappers['control']['container'] = 'div class="uk-width-2-3@s uk-form-controls"';
	$renderer->wrappers['label']['container'] = 'div class="uk-width-1-3@s uk-form-label"';
	$renderer->wrappers['control']['description'] = 'span class="form-text"'; // non uikit
	$renderer->wrappers['control']['errorcontainer'] = 'span class="form-control-feedback"'; // non uikit
	$renderer->wrappers['control']['.error'] = 'is-invalid'; // non uikit

	foreach ($form->getControls() as $control) {
		$type = $control->getOption('type');
		if ($type === 'button') {
			$control->getControlPrototype()->addClass(empty($usedPrimary) ? 'uk-button uk-button-primary' : 'uk-button uk-button-secondary');
			$usedPrimary = true;
		} elseif ($type === 'text') {
			$control->getControlPrototype()->addClass('uk-input');
		} elseif ($type === 'textarea') {
			$control->getControlPrototype()->addClass('uk-textarea');
		} elseif ($type === 'select') {
			$control->getControlPrototype()->addClass('uk-select');
		} elseif ($type === 'file') {
			$control->getControlPrototype()->addClass('uk-input');
		} elseif (in_array($type, ['checkbox', 'radio'], true)) {
			if ($control instanceof Nette\Forms\Controls\Checkbox) {
				$control->getLabelPrototype()->addClass('uk-checkbox');
			} else {
				$control->getItemLabelPrototype()->addClass('uk-radio');
			}
			$control->getControlPrototype()->addClass('form-check-input');
			$control->getSeparatorPrototype()->setName('div')->addClass('form-check');
		}
	}
}

$states = [
	'Andaman & Nicobar Islands' => 'Andaman & Nicobar Islands',
	'Andhra Pradesh' => 'Andhra Pradesh',
	'Arunachal Pradesh' => 'Arunachal Pradesh',
	'Assam' => 'Assam',
	'Bihar' => 'Bihar',
	'Chandigarh' => 'Chandigarh',
	'Chhattisgarh' => 'Chhattisgarh',
	'Dadra-Nagar Haveli & Daman-Diu' => 'Dadra-Nagar Haveli & Daman-Diu',
	'Delhi' => 'Delhi',
	'Goa' => 'Goa',
	'Gujarat' => 'Gujarat',
	'Haryana' => 'Haryana',
	'Himachal Pradesh' => 'Himachal Pradesh',
	'Jammu and Kashmir' => 'Jammu and Kashmir',
	'Jharkhand' => 'Jharkhand',
	'Karnataka' => 'Karnataka',
	'Kerala' => 'Kerala',
	'Ladakh' => 'Ladakh',
	'Lakshadweep' => 'Lakshadweep',
	'Madhya Pradesh' => 'Madhya Pradesh',
	'Maharashtra' => 'Maharashtra',
	'Manipur' => 'Manipur',
	'Meghalaya' => 'Meghalaya',
	'Mizoram' => 'Mizoram',
	'Nagaland' => 'Nagaland',
	'Odisha' => 'Odisha',
	'Puducherry' => 'Puducherry',
	'Punjab' => 'Punjab',
	'Rajasthan' => 'Rajasthan',
	'Sikkim' => 'Sikkim',
	'Tamil Nadu' => 'Tamil Nadu',
	'Telangana' => 'Telangana',
	'Tripura' => 'Tripura',
	'Uttar Pradesh' => 'Uttar Pradesh',
	'Uttarakhand' => 'Uttarakhand',
	'West Bengal' => 'West Bengal'
];

$form = new Form;
$form->onRender[] = 'makeUIkit';
$form->addText('name', 'Name:')
	->setRequired('Please fill your %label.');
$form->addEmail('email', 'Email:')
	->setRequired('Please fill your %label.');
$form->addText('designation', 'Designation:')
	->setRequired()
	->setHtmlAttribute('class', 'uk-width-1-2@s');
$form->addText('company', 'Company:')
	->setRequired()
	->setHtmlAttribute('class', 'uk-width-1-2@s');
$form->addCheckbox('printed', 'Please send me the printed edition. Delivered within India only.');

$form->addText('address', 'Address:')
	->setHtmlAttribute('class', 'uk-width-1-2@s')
	->addConditionOn($form['printed'], $form::EQUAL, true);
$form->addText('city', 'City:')
	->setHtmlAttribute('class', 'uk-width-1-2@s')
	->addConditionOn($form['printed'], $form::EQUAL, true);
$form->addSelect('state', 'State:', $states)
	->setHtmlAttribute('class', 'uk-width-1-2@s')
	->addConditionOn($form['printed'], $form::EQUAL, true);
$form->addInteger('pin', 'PIN:')
	->setHtmlAttribute('class', 'uk-width-1-2@s')
	->addConditionOn($form['printed'], $form::EQUAL, true)
		->addRule($form::PATTERN, 'Please enter a valid Indian PIN code', '^[1-9]{1}[0-9]{5}$');

$form->addSubmit('subscribe', 'Subscribe');


?>

<script pw-append="html-head" src="https://nette.github.io/resources/js/3/netteForms.min.js"></script>

<div id='content' class='uk-width-expand'>

	<div class="uk-child-width-1-2@m" uk-grid>
		<div>
			<?php
			$latest_mag = $pages->get("template=mag-issue, sort=-created");
			echo "<img class='uk-align-center' src='{$latest_mag->images->first->url}' alt='{$latest_mag->title}' />";	
			?>
		</div>
		<div>
			<h2>Subscribe!</h2>
			<?php $form->render() ?>
		</div>
	</div>
</div>

 

Link to comment
Share on other sites

  • 1 month later...

Hi @kalimati I don't have one at hand and have lots of client work to do. If your request is important I'm happy to help and you can request a quote via PM ? I'm also working on another forms project right now, so it might be interesting to hear your needs and discuss options...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...