Skip to content

Commit

Permalink
[Backoffice] Add TabHelper.
Browse files Browse the repository at this point in the history
  • Loading branch information
NoUseFreak committed Mar 24, 2015
1 parent 0f8f094 commit aaae6e2
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
67 changes: 67 additions & 0 deletions src/Clastic/BackofficeBundle/Form/TabHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* This file is part of the Clastic package.
*
* (c) Dries De Peuter <dries@nousefreak.be>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Clastic\BackofficeBundle\Form;

use Symfony\Component\Form\FormBuilderInterface;

/**
* TabHelper
*
* @author Dries De Peuter <dries@nousefreak.be>
*/
class TabHelper
{
/**
* @var FormBuilderInterface
*/
private $formBuilder;

/**
* @param FormBuilderInterface $formBuilder
*/
public function __construct(FormBuilderInterface $formBuilder)
{
$this->formBuilder = $formBuilder;
}

/**
* @param string $name
*
* @return FormBuilderInterface
*/
public function findTab($name)
{
return $this->formBuilder->get('tabs')->get($name);
}

/**
* Create a new tab and nest it under the tabs.
*
* @param string $name
* @param string $label
* @param array $options
*
* @return FormBuilderInterface The created tab.
*/
public function createTab($name, $label, $options = array())
{
$options = array_replace(
$options,
array(
'label' => $label,
'inherit_data' => true,
));

$tab = $this->formBuilder->create($name, 'tabs_tab', $options);
$this->formBuilder->get('tabs')->add($tab);

return $tab;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Clastic\NodeBundle\Form\Extension;

use Clastic\BackofficeBundle\Form\TabHelper;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
Expand All @@ -20,6 +21,11 @@
*/
abstract class AbstractNodeTypeExtension
{
/**
* @var TabHelper
*/
private $tabHelper;

/**
* {@inheritdoc}
*/
Expand All @@ -41,6 +47,14 @@ public function finishView(FormView $view, FormInterface $form, array $options)
{
}

/**
* @param FormBuilderInterface $builder
* @param string $name
*
* @deprecated Use TabHelper instead.
*
* @return FormBuilderInterface
*/
protected function findTab(FormBuilderInterface $builder, $name)
{
return $builder->get('tabs')->get($name);
Expand All @@ -53,6 +67,8 @@ protected function findTab(FormBuilderInterface $builder, $name)
* @param string $name
* @param array $options
*
* @deprecated Use TabHelper instead.
*
* @return FormBuilderInterface
*/
final protected function createTab(FormBuilderInterface $builder, $name, $options = array())
Expand All @@ -65,4 +81,18 @@ final protected function createTab(FormBuilderInterface $builder, $name, $option

return $builder->create($name, 'tabs_tab', $options);
}

/**
* @param FormBuilderInterface $builder
*
* @return TabHelper
*/
protected function getTabHelper(FormBuilderInterface $builder)
{
if (is_null($this->tabHelper)) {
$this->tabHelper = new TabHelper($builder);
}

return $this->tabHelper;
}
}

0 comments on commit aaae6e2

Please sign in to comment.