<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="fr">
	<id>http://www.e-glop.net/index.php?action=history&amp;feed=atom&amp;title=Un_hack_des_sfForm_sur_des_mod%C3%A8les_Sluggable</id>
	<title>Un hack des sfForm sur des modèles Sluggable - Historique des versions</title>
	<link rel="self" type="application/atom+xml" href="http://www.e-glop.net/index.php?action=history&amp;feed=atom&amp;title=Un_hack_des_sfForm_sur_des_mod%C3%A8les_Sluggable"/>
	<link rel="alternate" type="text/html" href="http://www.e-glop.net/index.php?title=Un_hack_des_sfForm_sur_des_mod%C3%A8les_Sluggable&amp;action=history"/>
	<updated>2026-05-21T18:04:18Z</updated>
	<subtitle>Historique des versions pour cette page sur le wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>http://www.e-glop.net/index.php?title=Un_hack_des_sfForm_sur_des_mod%C3%A8les_Sluggable&amp;diff=2383&amp;oldid=prev</id>
		<title>BeTa le 22 mars 2013 à 19:56</title>
		<link rel="alternate" type="text/html" href="http://www.e-glop.net/index.php?title=Un_hack_des_sfForm_sur_des_mod%C3%A8les_Sluggable&amp;diff=2383&amp;oldid=prev"/>
		<updated>2013-03-22T19:56:38Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;fr&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Version précédente&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Version du 22 mars 2013 à 19:56&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l59&quot;&gt;Ligne 59 :&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Ligne 59 :&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Cette solution est basée sur le nom &amp;quot;slug&amp;quot; de la colonne visée. ce n&amp;#039;est donc pas l&amp;#039;idéal. Disons que pour le moment &amp;quot;ça suffira&amp;quot;, en attendant de faire ça mieux.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Cette solution est basée sur le nom &amp;quot;slug&amp;quot; de la colonne visée. ce n&amp;#039;est donc pas l&amp;#039;idéal. Disons que pour le moment &amp;quot;ça suffira&amp;quot;, en attendant de faire ça mieux.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[Catégorie:Informatique]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[&lt;/ins&gt;[Catégorie:Informatique&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;]&lt;/ins&gt;]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>BeTa</name></author>
	</entry>
	<entry>
		<id>http://www.e-glop.net/index.php?title=Un_hack_des_sfForm_sur_des_mod%C3%A8les_Sluggable&amp;diff=2381&amp;oldid=prev</id>
		<title>BeTa le 22 mars 2013 à 19:56</title>
		<link rel="alternate" type="text/html" href="http://www.e-glop.net/index.php?title=Un_hack_des_sfForm_sur_des_mod%C3%A8les_Sluggable&amp;diff=2381&amp;oldid=prev"/>
		<updated>2013-03-22T19:56:15Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;fr&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Version précédente&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Version du 22 mars 2013 à 19:56&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l58&quot;&gt;Ligne 58 :&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Ligne 58 :&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Cette solution est basée sur le nom &amp;quot;slug&amp;quot; de la colonne visée. ce n&amp;#039;est donc pas l&amp;#039;idéal. Disons que pour le moment &amp;quot;ça suffira&amp;quot;, en attendant de faire ça mieux.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Cette solution est basée sur le nom &amp;quot;slug&amp;quot; de la colonne visée. ce n&amp;#039;est donc pas l&amp;#039;idéal. Disons que pour le moment &amp;quot;ça suffira&amp;quot;, en attendant de faire ça mieux.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[Catégorie:Informatique]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>BeTa</name></author>
	</entry>
	<entry>
		<id>http://www.e-glop.net/index.php?title=Un_hack_des_sfForm_sur_des_mod%C3%A8les_Sluggable&amp;diff=2380&amp;oldid=prev</id>
		<title>BeTa : Page créée avec « == Constat ==  Les sfForm bâtis sur des modèles implémentant le behaviour Sluggable plantent si deux objets ont les mêmes données permettant de calculer le slug : en ... »</title>
		<link rel="alternate" type="text/html" href="http://www.e-glop.net/index.php?title=Un_hack_des_sfForm_sur_des_mod%C3%A8les_Sluggable&amp;diff=2380&amp;oldid=prev"/>
		<updated>2013-03-22T19:41:53Z</updated>

		<summary type="html">&lt;p&gt;Page créée avec « == Constat ==  Les sfForm bâtis sur des modèles implémentant le behaviour Sluggable plantent si deux objets ont les mêmes données permettant de calculer le slug : en ... »&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Nouvelle page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Constat ==&lt;br /&gt;
&lt;br /&gt;
Les sfForm bâtis sur des modèles implémentant le behaviour Sluggable plantent si deux objets ont les mêmes données permettant de calculer le slug : en effet, avant comparaison dans la base, les calculs des deux slugs donnent le même résultat.&lt;br /&gt;
&lt;br /&gt;
Pour éviter les slugs dupliqués, Doctrine 1.2 appelle juste avant l&amp;#039;insert/update la fonction Doctrine_Template_Listener_Sluggable::getUniqueSlug() qui va chercher les doublons potentiels dans la base de données et qui offre une alternative unique pour le Doctrine_Record courant.&lt;br /&gt;
&lt;br /&gt;
Le problème est que Symfony pour sa part, vérifie dans ses sfForm l&amp;#039;unicité du slug pré-calculé mais non (encore) confronté au contenu de la table courante. Cela se passe dans le BaseForm courant, généré automatiquement au moment du ./symfony doctrine:build-forms via le template lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/data/generator/sfDoctrineForm/default/template/sfDoctrineFormGeneratedTemplate.php.&lt;br /&gt;
&lt;br /&gt;
== Solution ==&lt;br /&gt;
&lt;br /&gt;
Soit nous optons pour un hack pas très joli, soit on reprend le template. C&amp;#039;est cette seconde option, plus propre (même si elle touche au core de Symfony1), que nous choisissons.&lt;br /&gt;
&lt;br /&gt;
 // lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/data/generator/sfDoctrineForm/default/template/sfDoctrineFormGeneratedTemplate.php&lt;br /&gt;
 // Ligne 36:&lt;br /&gt;
 &amp;lt;?php if ($uniqueColumns = $this-&amp;gt;getUniqueColumnNames()): ?&amp;gt;&lt;br /&gt;
     $this-&amp;gt;validatorSchema-&amp;gt;setPostValidator(&lt;br /&gt;
 &amp;lt;?php if (count($uniqueColumns) &amp;gt; 1): ?&amp;gt;&lt;br /&gt;
       new sfValidatorAnd(array(&lt;br /&gt;
 &amp;lt;?php foreach ($uniqueColumns as $uniqueColumn): ?&amp;gt;&lt;br /&gt;
         new sfValidatorDoctrineUnique(array(&amp;#039;model&amp;#039; =&amp;gt; &amp;#039;&amp;lt;?php echo $this-&amp;gt;table-&amp;gt;getOption(&amp;#039;name&amp;#039;) ?&amp;gt;&amp;#039;, &amp;#039;column$&lt;br /&gt;
 &amp;lt;?php endforeach; ?&amp;gt;&lt;br /&gt;
       ))&lt;br /&gt;
 &amp;lt;?php else: ?&amp;gt;&lt;br /&gt;
       new sfValidatorDoctrineUnique(array(&amp;#039;model&amp;#039; =&amp;gt; &amp;#039;&amp;lt;?php echo $this-&amp;gt;table-&amp;gt;getOption(&amp;#039;name&amp;#039;) ?&amp;gt;&amp;#039;, &amp;#039;column&amp;#039; $&lt;br /&gt;
 &amp;lt;?php endif; ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Modifications à apporter ==&lt;br /&gt;
&lt;br /&gt;
 Index: lib/plugins/sfDoctrinePlugin/data/generator/sfDoctrineForm/default/template/sfDoctrineFormGeneratedTemplate.php&lt;br /&gt;
 ===================================================================&lt;br /&gt;
 --- lib/plugins/sfDoctrinePlugin/data/generator/sfDoctrineForm/default/template /sfDoctrineFormGeneratedTemplate.php	(révision 33643)&lt;br /&gt;
 +++ lib/plugins/sfDoctrinePlugin/data/generator/sfDoctrineForm/default/template/sfDoctrineFormGeneratedTemplate.php	(copie de travail)&lt;br /&gt;
 @@ -32,7 +32,10 @@&lt;br /&gt;
  &amp;lt;?php endforeach; ?&amp;gt;&lt;br /&gt;
      ));&lt;br /&gt;
  &lt;br /&gt;
 +&amp;lt;?php // LIBRINFO: 22/03/2013&lt;br /&gt;
  &amp;lt;?php if ($uniqueColumns = $this-&amp;gt;getUniqueColumnNames()): ?&amp;gt;&lt;br /&gt;
 +&amp;lt;?php foreach ( $uniqueColumns as $key =&amp;gt; $ucol ) if ( implode(&amp;quot;&amp;#039;, &amp;#039;&amp;quot;, $ucol) === &amp;#039;slug&amp;#039; ) unset($uniqueColumns[$key]); ?&amp;gt;&lt;br /&gt;
 +&amp;lt;?php if ( count($uniqueColumns) ): ?&amp;gt;&lt;br /&gt;
      $this-&amp;gt;validatorSchema-&amp;gt;setPostValidator(&lt;br /&gt;
  &amp;lt;?php if (count($uniqueColumns) &amp;gt; 1): ?&amp;gt;&lt;br /&gt;
        new sfValidatorAnd(array(&lt;br /&gt;
 @@ -44,6 +47,7 @@&lt;br /&gt;
        new sfValidatorDoctrineUnique(array(&amp;#039;model&amp;#039; =&amp;gt; &amp;#039;&amp;lt;?php echo $this-&amp;gt;table-&amp;gt;getOption(&amp;#039;name&amp;#039;) ?&amp;gt;&amp;#039;, &amp;#039;column&amp;#039; =&amp;gt; array(&amp;#039;&amp;lt;?php echo implode(&amp;quot;&amp;#039;, &amp;#039;&amp;quot;, $uniqueColumns[0]) ?&amp;gt;&amp;#039;)))&lt;br /&gt;
  &amp;lt;?php endif; ?&amp;gt;&lt;br /&gt;
      );&lt;br /&gt;
 +&amp;lt;?php endif ?&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  &amp;lt;?php endif; ?&amp;gt;&lt;br /&gt;
      $this-&amp;gt;widgetSchema-&amp;gt;setNameFormat(&amp;#039;&amp;lt;?php echo $this-&amp;gt;underscore($this-&amp;gt;modelName) ?&amp;gt;[%s]&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
Et là nous reconstruisons les formulaires :&lt;br /&gt;
&lt;br /&gt;
 ./symfony doctrine:build-forms&lt;br /&gt;
&lt;br /&gt;
== Limites ==&lt;br /&gt;
&lt;br /&gt;
Cette solution est basée sur le nom &amp;quot;slug&amp;quot; de la colonne visée. ce n&amp;#039;est donc pas l&amp;#039;idéal. Disons que pour le moment &amp;quot;ça suffira&amp;quot;, en attendant de faire ça mieux.&lt;/div&gt;</summary>
		<author><name>BeTa</name></author>
	</entry>
</feed>