@inheritdoc

Additionally, tracks attached behaviors to allow iterating over them.
12774
public function detachBehavior($name)
    {
        if (isset($this->_behaviors[$name])) {
            unset($this->_behaviors[$name]);
        }
        unset(self::$_names[get_class($this)]);

        return parent::detachBehavior($name);
    }
720502
protected function checkTraitsInjections()
    {
        $traits = $this->getUsedTraits();
        $reflection = new \ReflectionClass($this);
        foreach($traits as $trait) {
            $methodName = 'setTraitInjections' . $trait;
            if($reflection->hasMethod($methodName)) {
                $this->$methodName();
                $this->checkTraitInjections($trait);
            }
        }
    }
478469
public function detachBehaviors()
    {
        $this->ensureBehaviors();
        foreach ($this->__behaviors__ as $name => $behavior) {
            $this->detachBehavior($name);
        }
    }
379377
public function process_behavior($behavior, $method) {
        $behavior = Inflector::camelize($behavior);
        $model = $this->Model;

        if ($model->Behaviors->loaded($behavior) && $model->hasMethod($method)) {
            $model->Behaviors->{$behavior}->{$method}($model);

            $this->AdminToolbar->logAction(ActionLog::PROCESS, $model, '', __d('admin', 'Triggered %s.%s() process', array($behavior, $method)));
            $this->AdminToolbar->setFlashMessage(__d('admin', 'Processed %s.%s() for %s', array($behavior, $method, mb_strtolower($model->pluralName))));

        } else {
            $this->AdminToolbar->setFlashMessage(__d('admin', '%s does not allow this process', $model->singularName), 'is-error');
        }

        $this->redirect($this->referer());
    }
1315535
public function attachEvents()
    {
        $appEvents = $this->container->get('event')->getAppEvents();

        if (!empty($appEvents)) {
            foreach ($appEvents as $event => $namespace) {
                // attach all before and after event to handler
                $this->container->get('event')->attach("$event", $namespace);
            }
        }
    }
188078
final public function walk(callable $callback)
    {
        $callback($this);

        foreach ($this->getChildren() as $child) {
            $child->walk($callback);
        }
    }
1363411
public function attach(ActionEventDispatcher $events)
    {
        $this->trackHandler($events->attachListener(MessageDispatch::INITIALIZE, $this));
    }
981927
public function addStructuredDataAttachments(\AgentSIB\Diadoc\Api\Proto\Events\StructuredDataAttachment $value)
    {
        if ($this->StructuredDataAttachments === null) {
            $this->StructuredDataAttachments = new \Protobuf\MessageCollection();
        }

        $this->StructuredDataAttachments->add($value);
    }
1019307
public function attach(EventManagerInterface $events)
    {
        $this->listeners[] = $events->attach($this->eventBefore, array($this, 'prepareUpload'));
        $this->listeners[] = $events->attach($this->eventAfter, array($this, 'finalizeUpload'));
    }
39861
private static function apply(/* iterable */ $previous, callable $func): \Generator
    {
        foreach ($previous as $value) {
            $result = $func($value);
            if ($result instanceof \Generator) {
                yield from $result;
            } else {
                // Case of a plain old mapping function
                yield $result;
            }
        }
    }
1329640
protected function applyBehaviour(BehaviourInterface $behaviour, array $content = [])
    {
        if ($behaviour instanceof ExtendParent) {
            //We have to copy nodes from parent
            $this->nodes = $behaviour->getNode()->nodes;

            //Indication that this node has parent, meaning we have to handle blocks little
            //bit different way
            $this->extended = true;

            foreach ($behaviour->getAttributes() as $block => $blockContent) {
                $this->mountBlock($block, $blockContent);
            }

            return;
        }

        if ($behaviour instanceof CreateNode) {
            $this->mountBlock($behaviour->getName(), $content);

            return;
        }

        if ($behaviour instanceof ReplaceNode) {
            $this->nodes[] = $behaviour->createNode();
        }
    }
393429
public function attach($methods, $match, $callable)
    {
        if (is_string($methods)) {
            $methods = [$methods];
        }
        $route = new Route($methods, $callable);
        $this->storage[$match] = $route;
        return $route;
    }
1361291
public function attachListener(EventListener $listener)
    {
        foreach ($listener->getEventHandlers() as $name => $method) {
            if (! is_string($name)) {
                $name = $method;
                if (strpos($method, '.') !== false) {
                    $splits = explode('.', $method);
                    $method = $splits[count($splits) - 1];
                }
            }
            $this->attachHandler($name, array(
                $listener,
                $method
            ));
        }
    }
1166850
private function cascadeDetach($document, array &$visited)
    {
        $class = $this->dm->getClassMetadata(get_class($document));
        foreach ($class->propertyMetadata as $mapping) {
            if (!$mapping->isCascadeDetach) {
                continue;
            }
            $relatedDocuments = $class->getPropertyMetadata($mapping->name)->getValue($document);
            if (($relatedDocuments instanceof Collection || is_array($relatedDocuments))) {
                if ($relatedDocuments instanceof PersistentCollectionInterface) {
                    // Unwrap so that foreach() does not initialize
                    $relatedDocuments = $relatedDocuments->unwrap();
                }
                foreach ($relatedDocuments as $relatedDocument) {
                    $this->doDetach($relatedDocument, $visited);
                }
            } elseif ($relatedDocuments !== null) {
                $this->doDetach($relatedDocuments, $visited);
            }
        }
    }
752239
public function setAttachableObjects($attachableObjects)
    {
        if (!$this->isMergingData) {
            $attachableObjects = $this->mergePresetAttachableObjects($attachableObjects);
        }

        if (empty($attachableObjects) || is_string($attachableObjects)) {
            return false;
        }

        $out = [];
        foreach ($attachableObjects as $attType => $attMeta) {
            $label          = '';
            $filters        = [];
            $orders         = [];
            $numPerPage     = 0;
            $page           = 1;
            $skipForm       = 0;
            $formIdent      = null;
            $quickFormIdent = null;
            $faIcon         = '';
            $showIcon       = 1;
            $locked         = 0;
            $attOption      = ['label', 'filters', 'orders', 'num_per_page', 'page'];
            $attData        = array_diff_key($attMeta, $attOption);

            // Disable an attachable model
            if (isset($attMeta['active'])) {
                if (is_string($attMeta['active'])) {
                    $attMeta['active'] = $this->obj()->render($attMeta['active']);
                }
                if (!$attMeta['active']) {
                    continue;
                }
            }

            // Useful for replacing a pre-defined attachment type
            if (isset($attMeta['attachment_type'])) {
                $attType = $attMeta['attachment_type'];
            } else {
                $attMeta['attachment_type'] = $attType;
            }

            // Useful for attaching a pre-existing attachment
            $attId = (isset($attMeta['attachment_id']) ? $attMeta['attachment_id'] : null);

            if (isset($attMeta['label'])) {
                $label = $this->translator()->translation($attMeta['label']);
            }

            if (isset($attMeta['filters'])) {
                $filters = $attMeta['filters'];
            }

            if (isset($attMeta['orders'])) {
                $orders = $attMeta['orders'];
            }

            if (isset($attMeta['num_per_page'])) {
                $numPerPage = $attMeta['num_per_page'];
            }

            if (isset($attMeta['page'])) {
                $page = $attMeta['page'];
            }

            if (isset($attMeta['skip_form'])) {
                $skipForm = $attMeta['skip_form'];
            }

            if (isset($attMeta['form_ident'])) {
                $formIdent = $attMeta['form_ident'];
            }

            if (isset($attMeta['quick_form_ident'])) {
                $quickFormIdent = $attMeta['quick_form_ident'];
            }

            if (isset($attMeta['fa_icon']) && !empty($attMeta['fa_icon'])) {
                $faIcon = $attMeta['fa_icon'];
                if (!is_array($faIcon)) {
                    $faIcon = [$faIcon];
                }

                foreach ($faIcon as &$icon) {
                    $icon = 'fa fa-'.$icon;
                }
            } else {
                $attParts = explode('/', $attType);
                if (isset($this->defaultIcons[end($attParts)])) {
                    $faIcon = 'fa fa-'.$this->defaultIcons[end($attParts)];
                }
            }

            if (isset($attMeta['show_icon'])) {
                $showIcon = !!$attMeta['show_icon'];
            }

            if (isset($attMeta['locked'])) {
                $locked = $attMeta['locked'];

                if (is_string($locked)) {
                    $locked = $this->obj()->render($locked);
                }
            }

            $out[$attType] = [
                'att_id'           => $attId,
                'label'            => $label,
                'skipForm'         => $skipForm,
                'formIdent'        => $formIdent,
                'quickFormIdent'   => $quickFormIdent,
                'hasFaIcon'        => !!$faIcon,
                'faIcon'           => $faIcon,
                'showIcon'         => $showIcon,
                'filters'          => $filters,
                'orders'           => $orders,
                'page'             => $page,
                'numPerPage'       => $numPerPage,
                'locked'           => $locked,
                'data'             => $attData
            ];
        }

        $this->attachableObjects = $out;

        return $this;
    }
293766
public function ensureBehaviors()
    {
        if ($this->_behaviors === null) {
            $this->_behaviors = [];
            $this->attachBehaviorsInternal($this->behaviors());
        }
    }
1026079
public function track(TrackableInterface $trackable)
    {
        $tracked = false;
        if ($trackable instanceof Collection) {
            $this->trackCollection($trackable);
            $tracked = true;
        }

        if ($trackable instanceof PageController) {
            $this->trackCollection($trackable->getPageObject());
            $tracked = true;
        }

        if ($trackable instanceof BlockController) {
            if ($collection = $trackable->getCollectionObject()) {
                $this->trackBlocks($trackable->getCollectionObject(), [$trackable]);
                $tracked = true;
            }
        }

        if (!$tracked && $trackable instanceof FileTrackableInterface) {
            $this->trackFileTrackable($trackable);
        }
    }