plugin não responde no editor de artigos como paramentro

  • androide
  • Avatar de androide Autor do Tópico
  • Offline
  • JCB! Junior
  • JCB! Junior
Mais
9 anos 10 meses atrás #96859 por androide
androide created the topic: plugin não responde no editor de artigos como paramentro
Não achei a sessão correta para joomla 3.3, então estou postando minha duvida aqui.

Criei um plugin que deveria inserir novos parametros dentro do editor de artigos no joomla 3.3, o plugin funciona, mais insere a nova aba dentro das opções gerais de artigos, e não num artigo específico. Alguém já passou por isso?
php do plugin
<?php 


defined('JPATH_BASE') or die;


class plgContentAndreGaleria extends JPlugin
{

	 public function __construct(& $subject, $config)
   {
      parent::__construct($subject, $config);
      $this->loadLanguage();
   }

	public function onContentPrepareData($context, $data)
	{
		if (is_object($data))
		{


			$idArtigo = isset($data->id) ? $data->id : 0;

			if ($idArtigo >0)
			{

				// Load the profile data from the database.
				$db = JFactory::getDbo();
				$db->setQuery(
					'SELECT profile_key, profile_value FROM #__user_profiles' .
						' WHERE user_id = ' . $db->Quote($idArtigo) . " AND profile_key LIKE 'andregaleria.%'" .
						' ORDER BY ordering'
				);

				try
				{
					$results = $db->loadRowList();
				}
				catch (RuntimeException $e)
				{
					$this->_subject->setError($e->getMessage());
					return false;
				}

				// Merge the profile data.
				$data->andregaleria = array();

				foreach ($results as $v)
				{
					$k = str_replace('andregaleria.', '', $v&#91;0&#93;);
					$data->andregaleria&#91;$k&#93; = json_decode($v&#91;1&#93;, true);
					if ($data->andregaleria&#91;$k&#93; === null)
					{
						$data->andregaleria&#91;$k&#93; = $v&#91;1&#93;;
					}
				}
			}else{
				//le o formulário e insere o padrão
				JForm::addFormPath(__DIR__ . '/andregaleria');
				$form = new JForm('com_content.article');
				$form->loadFile('andregaleria', true);

				 $data->andregaleria = array();
		         foreach ($form->getFieldset('andregaleria') as $field) {
		               $data->andregaleria&#91;&#93; = array($field->fieldname, $field->value);
		         }


			}

		}

		return true;
	}

	//prepara o formulário
	public function onContentPrepareForm($form, $data)
	{




		if (!($form instanceof JForm))
		{

			$this->_subject->setError('JERROR_NOT_A_FORM');
			return false;
		}

		// Adiciona os campos extras
		JForm::addFormPath(__DIR__ . '/andregaleria');
		$form->loadFile('andregaleria', false);

      return true;
		
	} //fim da preparação do formulario



	public function onContentAfterSave($context, $article, $isNew)
	{
		$idArtigo = $article->id;

		if ($idArtigo && isset($article->andregaleria) && (count($article->andregaleria)))
		{
			try
			{

				$db = JFactory::getDbo();
				$query = $db->getQuery(true)
					->delete($db->quoteName('#__user_profiles'))
					->where($db->quoteName('user_id') . ' = ' . (int) $idArtigo)
					->where($db->quoteName('profile_key') . ' LIKE ' . $db->quote('andregaleria.%'));
				$db->setQuery($query);
				$db->execute();

				$tuples = array();
				$order = 1;

				foreach ($article->andregaleria as $k => $v)
				{
					$tuples&#91;&#93; = '(' . $idArtigo . ', ' . $db->quote('andregaleria.' . $k) . ', ' . $db->quote(json_encode($v)) . ', ' . $order++ . ')';
				}

				$db->setQuery('INSERT INTO #__user_profiles VALUES ' . implode(', ', $tuples));
				$db->execute();
			}
			catch (RuntimeException $e)
			{
				$this->_subject->setError($e->getMessage());
				return false;
			}
		}

		return true;
	}

	public function onContentAfterDelete($context, $article)
	{
		$idArtigo = $article->id;

		if ($idArtigo)
		{
			try
			{
				$db = JFactory::getDbo();
				$db->setQuery(
					'DELETE FROM #__user_profiles WHERE user_id = ' . $db->Quote($idArtigo) .
						" AND profile_key LIKE 'andregaleria.%'"
				);

				$db->execute();
			}
			catch (Exception $e)
			{
				$this->_subject->setError($e->getMessage());
				return false;
			}
		}

		return true;
	}





} //fim da class

xml dos campos
<form>
      <fields name="andregaleria">
         <fieldset name="andregaleria" label="Galeria">
            <field
               name="imagem1"
               type="media"
               directory="gianni"
               id="imagem1"
               description="Inserir Imagem para o banner"
               label="Imagem 1"
            />
           
         </fieldset>
      </fields>
   </form>

Please Entrar ou Registrar to join the conversation.