ソースを参照

Merge pull request #16249 from cakephp/issue-16247

Fix collection check.
Mark Story 4 年 前
コミット
41ce80827f

+ 4 - 5
src/View/Form/EntityContext.php

@@ -125,8 +125,11 @@ class EntityContext implements ContextInterface
         $table = $this->_context['table'];
         /** @var \Cake\Datasource\EntityInterface|iterable $entity */
         $entity = $this->_context['entity'];
+
+        $this->_isCollection = is_iterable($entity);
+
         if (empty($table)) {
-            if (is_iterable($entity)) {
+            if ($this->_isCollection) {
                 foreach ($entity as $e) {
                     $entity = $e;
                     break;
@@ -152,10 +155,6 @@ class EntityContext implements ContextInterface
                 'Unable to find table class for current entity.'
             );
         }
-        $this->_isCollection = (
-            is_array($entity) ||
-            $entity instanceof Traversable
-        );
 
         $alias = $this->_rootName = $table->getAlias();
         $this->_tables[$alias] = $table;

+ 2 - 0
tests/TestCase/View/Form/EntityContextTest.php

@@ -236,6 +236,8 @@ class EntityContextTest extends TestCase
 
         $result = $context->error('1.body');
         $this->assertEquals(['Not long enough'], $result);
+
+        $this->assertNull($context->val('0'));
     }
 
     /**