public function buildPaletteAndFields ($dc)
	{
		// Build the content block elements palette and fields only when editing a content element (see #5)
		if (\Input::get('act') != 'edit' && \Input::get('act') != 'show' && !isset($_GET['target']))
		{
			return;
		}
		
		$intId = (isset($_GET['target'])) ? explode('.', \Input::get('target'))[2] : $dc->id;
		
		$objContent = \ContentModel::findByPk($intId);
	
		if ($objContent === null)
		{
			return;
		}

		// Get block element
		$objElement = \ElementsModel::findOneByAlias($objContent->type);
			
		if ($objElement === null)
		{
			return;
		}

		// Add default palette (for type selection)
		$GLOBALS['TL_DCA']['tl_content']['palettes'][$objElement->alias] = '{type_legend},type';

		// Add pattern to palette
		$colPattern = \PatternModel::findVisibleByPid($objElement->id);

		if ($colPattern === null)
		{
			return;
		}
		
		$arrData = array();

		$colData = \DataModel::findByPid($intId);
		
		if ($colData !== null)
		{
			foreach ($colData as $objData)
			{
				$arrData[$objData->pattern] = $objData;
			}							
		}
	
		foreach($colPattern as $objPattern)
		{
			// Construct dca for pattern
			$strClass = Agoat\CustomContentElementsBundle\Contao\Pattern::findClass($objPattern->type);
			$bolData = Agoat\CustomContentElementsBundle\Contao\Pattern::hasData($objPattern->type);
				
			if (!class_exists($strClass))
			{
				\System::log('Pattern element class "'.$strClass.'" (pattern element "'.$objPattern->type.'") does not exist', __METHOD__, TL_ERROR);
			}
			else
			{
				if ($bolData && !isset($arrData[$objPattern->alias]))
				{
					$arrData[$objPattern->alias] = new \DataModel();
					$arrData[$objPattern->alias]->pid = $objContent->id;
					$arrData[$objPattern->alias]->pattern = $objPattern->alias;
			
					$arrData[$objPattern->alias]->save();
				}
				
				$objPatternClass = new $strClass($objPattern);
				$objPatternClass->pid = $objContent->id;
				$objPatternClass->pattern = $objPattern->alias;
				$objPatternClass->element = $objElement->alias;			
				$objPatternClass->data = $arrData[$objPattern->alias]; // Save data to the DCA		

				$objPatternClass->create();
			}
		}
	}