Created
April 10, 2013 13:15
-
-
Save mazenovi/5354527 to your computer and use it in GitHub Desktop.
Simple Tree Management with Symfony2 / Propel / AdmigeneratorGeneratorBundle with forbidden path disabled
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Twig Configuration | |
twig: | |
form: | |
resources: | |
- 'MazenoviLightCmsBundle:Form:fields.html.twig' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Mazenovi\LightCmsBundle\Form\Type\Folder; | |
use Admingenerated\MazenoviLightCmsBundle\Form\BaseFolderType\EditType as BaseEditType; | |
use Symfony\Component\Form\FormBuilderInterface; | |
use Symfony\Component\Form\FormView; | |
use Symfony\Component\Form\FormInterface; | |
use Mazenovi\LightCmsBundle\Model\FolderQuery; | |
use Mazenovi\LightCmsBundle\Form\EventListener\DisableNestedPathSubscriber; | |
class EditType extends BaseEditType | |
{ | |
public function finishView(FormView $view, FormInterface $form, array $options) | |
{ | |
//http://stackoverflow.com/questions/14344639/symfony-2form-how-to-disable-specific-item-in-form-choice-type | |
$nested_folder_ids = array(); | |
$nested_folder = FolderQuery::create()->childrenOf($view->vars['value'])->find(); | |
array_walk( | |
$nested_folder, | |
function($val, $key) use(&$nested_folder_ids){ | |
$nested_folder_ids[] = $val->getId(); | |
} | |
); | |
foreach ($view->children['parent_folder']->vars['choices'] as $parent) { | |
if(in_array($parent->data->getId(), $nested_folder_ids) || $parent->data->getId() == $view->vars['value']->getId()) | |
{ | |
$parent->disabled = 'disabled'; | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% block choice_widget_options %} | |
{% spaceless %} | |
{% for group_label, choice in options %} | |
{% if choice is iterable %} | |
<optgroup label="{{ group_label|trans({}, translation_domain) }}"> | |
{% set options = choice %} | |
{{ block('choice_widget_options') }} | |
</optgroup> | |
{% else %} | |
<option value="{{ choice.value }}"{% if choice is selectedchoice(value) %} selected="selected"{% endif %} {% if choice.disabled is defined %} disabled="{{ choice.disabled }}"{% endif %}>{{ choice.label|trans({}, translation_domain) }}</option> | |
{% endif %} | |
{% endfor %} | |
{% endspaceless %} | |
{% endblock choice_widget_options %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment