public function toggleVisibility($intId, $blnVisible, Contao\DataContainer $dc=null)
	{
		// Set the ID and action
		Contao\Input::setGet('id', $intId);
		Contao\Input::setGet('act', 'toggle');

		if ($dc)
		{
			$dc->id = $intId; // see #8043
		}

		// Trigger the onload_callback
		if (\is_array($GLOBALS['TL_DCA']['tl_form_field']['config']['onload_callback']))
		{
			foreach ($GLOBALS['TL_DCA']['tl_form_field']['config']['onload_callback'] as $callback)
			{
				if (\is_array($callback))
				{
					$this->import($callback[0]);
					$this->{$callback[0]}->{$callback[1]}($dc);
				}
				elseif (\is_callable($callback))
				{
					$callback($dc);
				}
			}
		}

		// Check the field access
		if (!$this->User->hasAccess('tl_form_field::invisible', 'alexf'))
		{
			throw new Contao\CoreBundle\Exception\AccessDeniedException('Not enough permissions to publish/unpublish form field ID ' . $intId . '.');
		}

		// Set the current record
		if ($dc)
		{
			$objRow = $this->Database->prepare("SELECT * FROM tl_form_field WHERE id=?")
									 ->limit(1)
									 ->execute($intId);

			if ($objRow->numRows)
			{
				$dc->activeRecord = $objRow;
			}
		}

		$objVersions = new Contao\Versions('tl_form_field', $intId);
		$objVersions->initialize();

		// Reverse the logic (form fields have invisible=1)
		$blnVisible = !$blnVisible;

		// Trigger the save_callback
		if (\is_array($GLOBALS['TL_DCA']['tl_form_field']['fields']['invisible']['save_callback']))
		{
			foreach ($GLOBALS['TL_DCA']['tl_form_field']['fields']['invisible']['save_callback'] as $callback)
			{
				if (\is_array($callback))
				{
					$this->import($callback[0]);
					$blnVisible = $this->{$callback[0]}->{$callback[1]}($blnVisible, $dc);
				}
				elseif (\is_callable($callback))
				{
					$blnVisible = $callback($blnVisible, $dc);
				}
			}
		}

		$time = time();

		// Update the database
		$this->Database->prepare("UPDATE tl_form_field SET tstamp=$time, invisible='" . ($blnVisible ? '1' : '') . "' WHERE id=?")
					   ->execute($intId);

		if ($dc)
		{
			$dc->activeRecord->tstamp = $time;
			$dc->activeRecord->invisible = ($blnVisible ? '1' : '');
		}

		// Trigger the onsubmit_callback
		if (\is_array($GLOBALS['TL_DCA']['tl_form_field']['config']['onsubmit_callback']))
		{
			foreach ($GLOBALS['TL_DCA']['tl_form_field']['config']['onsubmit_callback'] as $callback)
			{
				if (\is_array($callback))
				{
					$this->import($callback[0]);
					$this->{$callback[0]}->{$callback[1]}($dc);
				}
				elseif (\is_callable($callback))
				{
					$callback($dc);
				}
			}
		}

		$objVersions->create();
	}
public function toggleVisibility($intId, $blnVisible, Contao\DataContainer $dc=null)
	{
		
		Contao\Input::setGet('id', $intId);
		Contao\Input::setGet('act', 'toggle');

		if ($dc)
		{
			$dc->id = $intId; 
		}

		
		if (\is_array($GLOBALS['TL_DCA']['tl_form_field']['config']['onload_callback']))
		{
			foreach ($GLOBALS['TL_DCA']['tl_form_field']['config']['onload_callback'] as $callback)
			{
				if (\is_array($callback))
				{
					$this->import($callback[0]);
					$this->{$callback[0]}->{$callback[1]}($dc);
				}
				elseif (\is_callable($callback))
				{
					$callback($dc);
				}
			}
		}

		
		if (!$this->User->hasAccess('tl_form_field::invisible', 'alexf'))
		{
			throw new Contao\CoreBundle\Exception\AccessDeniedException('Not enough permissions to publish/unpublish form field ID ' . $intId . '.');
		}

		
		if ($dc)
		{
			$objRow = $this->Database->prepare("SELECT * FROM tl_form_field WHERE id=?")
									 ->limit(1)
									 ->execute($intId);

			if ($objRow->numRows)
			{
				$dc->activeRecord = $objRow;
			}
		}

		$objVersions = new Contao\Versions('tl_form_field', $intId);
		$objVersions->initialize();

		
		$blnVisible = !$blnVisible;

		
		if (\is_array($GLOBALS['TL_DCA']['tl_form_field']['fields']['invisible']['save_callback']))
		{
			foreach ($GLOBALS['TL_DCA']['tl_form_field']['fields']['invisible']['save_callback'] as $callback)
			{
				if (\is_array($callback))
				{
					$this->import($callback[0]);
					$blnVisible = $this->{$callback[0]}->{$callback[1]}($blnVisible, $dc);
				}
				elseif (\is_callable($callback))
				{
					$blnVisible = $callback($blnVisible, $dc);
				}
			}
		}

		$time = time();

		
		$this->Database->prepare("UPDATE tl_form_field SET tstamp=$time, invisible='" . ($blnVisible ? '1' : '') . "' WHERE id=?")
					   ->execute($intId);

		if ($dc)
		{
			$dc->activeRecord->tstamp = $time;
			$dc->activeRecord->invisible = ($blnVisible ? '1' : '');
		}

		
		if (\is_array($GLOBALS['TL_DCA']['tl_form_field']['config']['onsubmit_callback']))
		{
			foreach ($GLOBALS['TL_DCA']['tl_form_field']['config']['onsubmit_callback'] as $callback)
			{
				if (\is_array($callback))
				{
					$this->import($callback[0]);
					$this->{$callback[0]}->{$callback[1]}($dc);
				}
				elseif (\is_callable($callback))
				{
					$callback($dc);
				}
			}
		}

		$objVersions->create();
	}
public function toggleVisibility ( $ intId , $ blnVisible , Contao \ DataContainer $ dc = null ) { // Set the ID and action Contao \ Input :: setGet ( 'id' , $ intId ) ; Contao \ Input :: setGet ( 'act' , 'toggle' ) ; if ( $ dc ) { $ dc -> id = $ intId ; // see #8043 } // Trigger the onload_callback if ( \ is_array ( $ GLOBALS [ 'TL_DCA' ] [ 'tl_form_field' ] [ 'config' ] [ 'onload_callback' ] ) ) { foreach ( $ GLOBALS [ 'TL_DCA' ] [ 'tl_form_field' ] [ 'config' ] [ 'onload_callback' ] as $ callback ) { if ( \ is_array ( $ callback ) ) { $ this -> import ( $ callback [ 0 ] ) ; $ this -> { $ callback [ 0 ] } -> { $ callback [ 1 ] } ( $ dc ) ; } elseif ( \ is_callable ( $ callback ) ) { $ callback ( $ dc ) ; } } } // Check the field access if ( ! $ this -> User -> hasAccess ( 'tl_form_field::invisible' , 'alexf' ) ) { throw new Contao \ CoreBundle \ Exception \ AccessDeniedException ( 'Not enough permissions to publish/unpublish form field ID ' . $ intId . '.' ) ; } // Set the current record if ( $ dc ) { $ objRow = $ this -> Database -> prepare ( "SELECT * FROM tl_form_field WHERE id=?" ) -> limit ( 1 ) -> execute ( $ intId ) ; if ( $ objRow -> numRows ) { $ dc -> activeRecord = $ objRow ; } } $ objVersions = new Contao \ Versions ( 'tl_form_field' , $ intId ) ; $ objVersions -> initialize ( ) ; // Reverse the logic (form fields have invisible=1) $ blnVisible = ! $ blnVisible ; // Trigger the save_callback if ( \ is_array ( $ GLOBALS [ 'TL_DCA' ] [ 'tl_form_field' ] [ 'fields' ] [ 'invisible' ] [ 'save_callback' ] ) ) { foreach ( $ GLOBALS [ 'TL_DCA' ] [ 'tl_form_field' ] [ 'fields' ] [ 'invisible' ] [ 'save_callback' ] as $ callback ) { if ( \ is_array ( $ callback ) ) { $ this -> import ( $ callback [ 0 ] ) ; $ blnVisible = $ this -> { $ callback [ 0 ] } -> { $ callback [ 1 ] } ( $ blnVisible , $ dc ) ; } elseif ( \ is_callable ( $ callback ) ) { $ blnVisible = $ callback ( $ blnVisible , $ dc ) ; } } } $ time = time ( ) ; // Update the database $ this -> Database -> prepare ( "UPDATE tl_form_field SET tstamp=$time, invisible='" . ( $ blnVisible ? '1' : '' ) . "' WHERE id=?" ) -> execute ( $ intId ) ; if ( $ dc ) { $ dc -> activeRecord -> tstamp = $ time ; $ dc -> activeRecord -> invisible = ( $ blnVisible ? '1' : '' ) ; } // Trigger the onsubmit_callback if ( \ is_array ( $ GLOBALS [ 'TL_DCA' ] [ 'tl_form_field' ] [ 'config' ] [ 'onsubmit_callback' ] ) ) { foreach ( $ GLOBALS [ 'TL_DCA' ] [ 'tl_form_field' ] [ 'config' ] [ 'onsubmit_callback' ] as $ callback ) { if ( \ is_array ( $ callback ) ) { $ this -> import ( $ callback [ 0 ] ) ; $ this -> { $ callback [ 0 ] } -> { $ callback [ 1 ] } ( $ dc ) ; } elseif ( \ is_callable ( $ callback ) ) { $ callback ( $ dc ) ; } } } $ objVersions -> create ( ) ; }
Toggle the visibility of a form field

@param integer              $intId
@param boolean              $blnVisible
@param Contao\DataContainer $dc
Toggle the visibility of a form field